It means that the 'th' you are looking at (which is only the first
'th' in each table) doesn't have a class of 'asc'.

  http://docs.jquery.com/Core#index.28_subject_.29

It looks like you're trying to loop over each 'th' in each table try this:

$(document).ready(function() {
        $("table.simple").each(function() {
                $('th',this).each(function(i) {
                        if ( this.is('.asc') )
                                alert(i);
                });
        });
});

Karl Rudd

On 3/1/07, Jonathan Freeman <[EMAIL PROTECTED]> wrote:
> I'm trying to get my head around this method and I'm getting results
> unexpected results. I'm trying to get the index number of the th's that
> have the '.asc' class. Any ideas why the second one is returning -1 ?
> Thank you! :)
>
> <html>
> <head>
>         <script src="jquery.js" type="text/javascript"></script>
>         <script>
>         $(document).ready(function() {
>                 $("table.simple").each(function() {
>                         var x = $('th',this).index($('.asc')[0]);
>                         alert(x);
>                         //first returns 2, as expected
>                         //second returns -1, should it be 0?
>                 });
>         });
>         </script>
> </head>
>
> <body>
> <table class="simple">
>         <thead>
>                 <tr>
>                         <th>Column 1</th>
>                         <th>Column 2</th>
>                         <th class="asc">Column 3</th>
>                 </tr>
>         </thead>
>         <tbody>
>                 <tr>
>                         <td>Data 1</td>
>                         <td>Data 2</td>
>                         <td>Data 3</td>
>                 </tr>
>         </tbody>
> </table>
> <table class="simple">
>         <thead>
>                 <tr>
>                         <th class="asc">Column 1</th>
>                         <th>Column 2</th>
>                         <th>Column 3</th>
>                 </tr>
>         </thead>
>         <tbody>
>                 <tr>
>                         <td>Data 1</td>
>                         <td>Data 2</td>
>                         <td>Data 3</td>
>                 </tr>
>         </tbody>
> </table>
> </body>
> </html>
>
>
>
>
> ____________________________________________________________________________________
> Don't pick lemons.
> See all the new 2007 cars at Yahoo! Autos.
> http://autos.yahoo.com/new_cars.html
>
> _______________________________________________
> jQuery mailing list
> discuss@jquery.com
> http://jquery.com/discuss/
>

_______________________________________________
jQuery mailing list
discuss@jquery.com
http://jquery.com/discuss/

Reply via email to