[jQuery] Re: tbody:first-child & thead

2009-02-25 Thread Alex Wibowo
Hi Ricardo

Thats great... thx a lot!

On Thu, Feb 26, 2009 at 5:06 AM, ricardobeat  wrote:

>
> Tables have native properties which are much faster to access:
>
> $('#myTable')[0].rows.length //number of rows
> $('#myTable')[0].tBodies[0].rows.length //number of rows in the first
> tbody
>
> cheers,
> - ricardo
>
> On Feb 25, 5:25 am, Alex Wibowo  wrote:
> > Hi all,
> > I have a code that counts the number of rows in a table...
> >
> > the table looks like:
> >
> > 
> >   
> >...
> >
> >
> >
> > 
> >  
> > 
> >   
> > 
> >
> > and my jquery looks like:
> >
> > $("#myTable  tbody:first-child  tr").length;
> >
> > strange enough that always returns 0.
> > but if i remove the thead from the table... then it will return the
> correct
> > number of rows..
> >
> > or alternatively, i can keep the thead, but use the following instead:
> >
> > $("#myTable  tbody  tr").length;
> >
> > i.e. without specifying first-child.
> >
> > Can anyone explain this behaviour?
> >
> > THanks a lot!
> >
> > --
> > Best regards,
> >
> > WiB
>



-- 
Best regards,


WiB


[jQuery] Re: tbody:first-child & thead

2009-02-25 Thread ricardobeat

Tables have native properties which are much faster to access:

$('#myTable')[0].rows.length //number of rows
$('#myTable')[0].tBodies[0].rows.length //number of rows in the first
tbody

cheers,
- ricardo

On Feb 25, 5:25 am, Alex Wibowo  wrote:
> Hi all,
> I have a code that counts the number of rows in a table...
>
> the table looks like:
>
> 
>   
>    ...
>    
>
>    
>         
>          
>         
>   
> 
>
> and my jquery looks like:
>
> $("#myTable  tbody:first-child  tr").length;
>
> strange enough that always returns 0.
> but if i remove the thead from the table... then it will return the correct
> number of rows..
>
> or alternatively, i can keep the thead, but use the following instead:
>
> $("#myTable  tbody  tr").length;
>
> i.e. without specifying first-child.
>
> Can anyone explain this behaviour?
>
> THanks a lot!
>
> --
> Best regards,
>
> WiB


[jQuery] Re: tbody:first-child & thead

2009-02-25 Thread Mauricio (Maujor) Samy Silva
jQuery uses the power of CSS selectors.

:first-child is an CSS pseudo-class selector and eq() isn't from CSS sintax.

Further reading: 
http://www.456bereastreet.com/archive/200509/css_21_selectors_part_1/

Maurício
  -Mensagem Original- 
  De: Alex Wibowo 
  Para: jquery-en@googlegroups.com 
  Enviada em: quarta-feira, 25 de fevereiro de 2009 09:43
  Assunto: [jQuery] Re: tbody:first-child & thead


  ahhh
  ok ... now i get it. sorry for wasting your time, guys...
  i thought its E F:first-child reads "the first child of E of type F"... i 
didn't know that it has to explicitly be the first child.

  I didnt even know that this syntax is CSS thing i thought it is jQuery's 
syntax.

  Thanks for pointing out to that website!

  Question   is:first&  :eq(n)  also a CSS syntax?


  Thanks again!



  On Wed, Feb 25, 2009 at 11:29 PM, Mauricio (Maujor) Samy Silva 
 wrote:

Ops! my faul! sorry.
Previous post errata.

Read: ...BEFORE the F element ...

instead of:  ...BEFORE the E element... 



  -Mensagem Original- 
  De: Mauricio (Maujor) Samy Silva 
  Para: jquery-en@googlegroups.com 
  Enviada em: quarta-feira, 25 de fevereiro de 2009 09:24
  Assunto: Re: [jQuery] Re: tbody:first-child & thead


  Hi Alex,

  1-) Doesn't work because * E F:first-child * pseudo-class selector 
matches the F element that is the first child of the E element ONLY if there 
isn't another element BEFORE the E element within the parent E. See specs at: 
http://www.w3.org/TR/CSS2/selector.html#first-child

   2-) If you have a thead or/and a tbody in your markup, to select the 
first thead use the pseudo-class :eq instead. 

  $("#myTable tbody:eq(0) tr").length )

  Maurício
-Mensagem Original- 
De: Alex Wibowo 
Para: jquery-en@googlegroups.com 
Enviada em: quarta-feira, 25 de fevereiro de 2009 08:33
Assunto: [jQuery] Re: tbody:first-child & thead


Hi Karl.. thanks for the reply...

what i actually wanted is to select the first tbody thats why i 
specified tbody:first-child there
since a table can have multiple tbody... i want to select the first 
tbody.

What I didnt understand is about the thead..

the following works



   

 

  


$("#myTable  tbody:first-child  tr").length;


but this doesnt work:




   
   
...
   
  

   

 

  


$("#myTable  tbody:first-child  tr").length;


I dont know how  thead causes the second code above not to work...





On Wed, Feb 25, 2009 at 8:11 PM, Karl Rudd  wrote:


  tbody:first-child doesn't select the "first child of the tbody" it
  says "select the tbody that is the 'first-child' of it's parent".

  So what you are actually wanting to say is:

  $("#myTable tbody tr:first-child")

  Which is "select the tr that is the first child of tbody"

  http://docs.jquery.com/Selectors/firstChild

  Karl Rudd


  On Wed, Feb 25, 2009 at 8:08 PM, Alex Wibowo  
wrote:
  > sorry i should say
  > "how does that explain the behaviour when there's no thead" 
(because it
  > works when thead doesnt exist)
  >
  > On Wed, Feb 25, 2009 at 8:06 PM, Alex Wibowo  
wrote:
  >>
  >> how does that explain the behaviour when there's thead then??
  >>
  >>
  >> On Wed, Feb 25, 2009 at 7:47 PM, David Muir  
wrote:
  >>>
  >>> It's because tbody:first-child is already selecting the tr, so 
you're
  >>> effectively doing:
  >>> tbody tr tr (where the first tr is the first child of tbody)
  >>>
  >>> Cheers,
  >>> David
  >>>
  >>>
  >>> Alex Wibowo wrote:
  >>>>
  >>>> Hi all,
  >>>>
  >>>> I have a code that counts the number of rows in a table...
  >>>>
  >>>> the table looks like:
  >>>>
  >>>> 
  >>>>  
  >>>>   ...
  >>>>   
  >>>>
  >>>>   
  >>>>
  >>>> 
  &g

[jQuery] Re: tbody:first-child & thead

2009-02-25 Thread Alex Wibowo
ahhh
ok ... now i get it. sorry for wasting your time, guys...
i thought its E F:first-child reads "the first child of E of type F"... i
didn't know that it has to explicitly be the first child.

I didnt even know that this syntax is CSS thing i thought it is jQuery's
syntax.

Thanks for pointing out to that website!

Question   is:first&  :eq(n)  also a CSS syntax?


Thanks again!


On Wed, Feb 25, 2009 at 11:29 PM, Mauricio (Maujor) Samy Silva <
css.mau...@gmail.com> wrote:

>  Ops! my faul! sorry.
> Previous post errata.
>
> Read: ...BEFORE the F element ...
>
> instead of:  ...BEFORE the E element...
>
>
>
>
> -Mensagem Original-
> *De:* Mauricio (Maujor) Samy Silva 
> *Para:* jquery-en@googlegroups.com
> *Enviada em:* quarta-feira, 25 de fevereiro de 2009 09:24
> *Assunto:* Re: [jQuery] Re: tbody:first-child & thead
>
> Hi Alex,
>
> 1-) Doesn't work because * E F:first-child * pseudo-class selector matches
> the F element that is the first child of the E element ONLY if there
> isn't another element BEFORE the E element within the parent E. See specs
> at: http://www.w3.org/TR/CSS2/selector.html#first-child
>
>  2-) If you have a thead or/and a tbody in your markup, to select the first
> thead use the pseudo-class :eq instead.
>
> $("#myTable tbody:eq(0) tr").length )
>
> Maurício
>
> -Mensagem Original-----
> *De:* Alex Wibowo 
> *Para:* jquery-en@googlegroups.com
> *Enviada em:* quarta-feira, 25 de fevereiro de 2009 08:33
> *Assunto:* [jQuery] Re: tbody:first-child & thead
>
> Hi Karl.. thanks for the reply...
>
> what i actually wanted is to select the first tbody thats why i
> specified tbody:first-child there
> since a table can have multiple tbody... i want to select the first tbody.
>
> What I didnt understand is about the thead..
>
> the following works
>
> 
>
> 
>  
> 
>   
> 
>
> $("#myTable  tbody:first-child  tr").length;
>
>
> but this doesnt work:
>
> 
>
>
> ...
>
>   
>
> 
>  
> 
>   
> 
>
> $("#myTable  tbody:first-child  tr").length;
>
>
> I dont know how  thead causes the second code above not to work...
>
>
>
> On Wed, Feb 25, 2009 at 8:11 PM, Karl Rudd  wrote:
>
>>
>> tbody:first-child doesn't select the "first child of the tbody" it
>> says "select the tbody that is the 'first-child' of it's parent".
>>
>> So what you are actually wanting to say is:
>>
>> $("#myTable tbody tr:first-child")
>>
>> Which is "select the tr that is the first child of tbody"
>>
>> http://docs.jquery.com/Selectors/firstChild
>>
>> Karl Rudd
>>
>> On Wed, Feb 25, 2009 at 8:08 PM, Alex Wibowo 
>> wrote:
>> > sorry i should say
>> > "how does that explain the behaviour when there's no thead" (because it
>> > works when thead doesnt exist)
>> >
>> > On Wed, Feb 25, 2009 at 8:06 PM, Alex Wibowo 
>> wrote:
>> >>
>> >> how does that explain the behaviour when there's thead then??
>> >>
>> >>
>> >> On Wed, Feb 25, 2009 at 7:47 PM, David Muir 
>> wrote:
>> >>>
>> >>> It's because tbody:first-child is already selecting the tr, so you're
>> >>> effectively doing:
>> >>> tbody tr tr (where the first tr is the first child of tbody)
>> >>>
>> >>> Cheers,
>> >>> David
>> >>>
>> >>>
>> >>> Alex Wibowo wrote:
>> >>>>
>> >>>> Hi all,
>> >>>>
>> >>>> I have a code that counts the number of rows in a table...
>> >>>>
>> >>>> the table looks like:
>> >>>>
>> >>>> 
>> >>>>  
>> >>>>   ...
>> >>>>   
>> >>>>
>> >>>>   
>> >>>>
>> >>>> 
>> >>>>
>> >>>>  
>> >>>> 
>> >>>>
>> >>>>
>> >>>> and my jquery looks like:
>> >>>>
>> >>>> $("#myTable  tbody:first-child  tr").length;
>> >>>>
>> >>>> strange enough that always returns 0.
>> >>>> but if i remove the thead from the table... then it will return the
>> >>>> correct number of rows..
>> >>>>
>> >>>> or alternatively, i can keep the thead, but use the following
>> instead:
>> >>>>
>> >>>> $("#myTable  tbody  tr").length;
>> >>>>
>> >>>> i.e. without specifying first-child.
>> >>>>
>> >>>> Can anyone explain this behaviour?
>> >>>>
>> >>>>
>> >>>>
>> >>>> THanks a lot!
>> >>>>
>> >>>>
>> >>>>
>> >>>> --
>> >>>> Best regards,
>> >>>>
>> >>>>
>> >>>> WiB
>> >>>>
>> >>>
>> >>
>> >>
>> >>
>> >> --
>> >> Best regards,
>> >>
>> >>
>> >> WiB
>> >>
>> >
>> >
>> >
>> > --
>> > Best regards,
>> >
>> >
>> > WiB
>> >
>> >
>>
>
>
>
> --
> Best regards,
>
>
> WiB
>
>


-- 
Best regards,


WiB


[jQuery] Re: tbody:first-child & thead

2009-02-25 Thread Mauricio (Maujor) Samy Silva
Ops! my faul! sorry.
Previous post errata.

Read: ...BEFORE the F element ...

instead of:  ...BEFORE the E element... 



  -Mensagem Original- 
  De: Mauricio (Maujor) Samy Silva 
  Para: jquery-en@googlegroups.com 
  Enviada em: quarta-feira, 25 de fevereiro de 2009 09:24
  Assunto: Re: [jQuery] Re: tbody:first-child & thead


  Hi Alex,

  1-) Doesn't work because * E F:first-child * pseudo-class selector matches 
the F element that is the first child of the E element ONLY if there isn't 
another element BEFORE the E element within the parent E. See specs at: 
http://www.w3.org/TR/CSS2/selector.html#first-child

   2-) If you have a thead or/and a tbody in your markup, to select the first 
thead use the pseudo-class :eq instead. 

  $("#myTable tbody:eq(0) tr").length )

  Maurício
-Mensagem Original- 
De: Alex Wibowo 
Para: jquery-en@googlegroups.com 
Enviada em: quarta-feira, 25 de fevereiro de 2009 08:33
    Assunto: [jQuery] Re: tbody:first-child & thead


Hi Karl.. thanks for the reply...

what i actually wanted is to select the first tbody thats why i 
specified tbody:first-child there
since a table can have multiple tbody... i want to select the first tbody.

What I didnt understand is about the thead..

the following works



   

 

  


$("#myTable  tbody:first-child  tr").length;


but this doesnt work:




   
   
...
   
  

   

 

  


$("#myTable  tbody:first-child  tr").length;


I dont know how  thead causes the second code above not to work...





On Wed, Feb 25, 2009 at 8:11 PM, Karl Rudd  wrote:


  tbody:first-child doesn't select the "first child of the tbody" it
  says "select the tbody that is the 'first-child' of it's parent".

  So what you are actually wanting to say is:

  $("#myTable tbody tr:first-child")

  Which is "select the tr that is the first child of tbody"

  http://docs.jquery.com/Selectors/firstChild

  Karl Rudd


  On Wed, Feb 25, 2009 at 8:08 PM, Alex Wibowo  wrote:
  > sorry i should say
  > "how does that explain the behaviour when there's no thead" (because it
  > works when thead doesnt exist)
  >
  > On Wed, Feb 25, 2009 at 8:06 PM, Alex Wibowo  
wrote:
  >>
  >> how does that explain the behaviour when there's thead then??
  >>
  >>
  >> On Wed, Feb 25, 2009 at 7:47 PM, David Muir  
wrote:
  >>>
  >>> It's because tbody:first-child is already selecting the tr, so you're
  >>> effectively doing:
  >>> tbody tr tr (where the first tr is the first child of tbody)
  >>>
  >>> Cheers,
  >>> David
  >>>
  >>>
  >>> Alex Wibowo wrote:
  >>>>
  >>>> Hi all,
  >>>>
  >>>> I have a code that counts the number of rows in a table...
  >>>>
  >>>> the table looks like:
  >>>>
  >>>> 
  >>>>  
  >>>>   ...
  >>>>   
  >>>>
  >>>>   
  >>>>
  >>>> 
  >>>>
  >>>>  
  >>>> 
  >>>>
  >>>>
  >>>> and my jquery looks like:
  >>>>
  >>>> $("#myTable  tbody:first-child  tr").length;
  >>>>
  >>>> strange enough that always returns 0.
  >>>> but if i remove the thead from the table... then it will return the
  >>>> correct number of rows..
  >>>>
  >>>> or alternatively, i can keep the thead, but use the following 
instead:
  >>>>
  >>>> $("#myTable  tbody  tr").length;
  >>>>
  >>>> i.e. without specifying first-child.
  >>>>
  >>>> Can anyone explain this behaviour?
  >>>>
  >>>>
  >>>>
  >>>> THanks a lot!
  >>>>
  >>>>
  >>>>
  >>>> --
  >>>> Best regards,
  >>>>
  >>>>
  >>>> WiB
  >>>>
  >>>
  >>
  >>
  >>
  >> --
  >> Best regards,
  >>
  >>
  >> WiB
  >>
  >
  >
  >
  > --
  > Best regards,
  >
  >
  > WiB
  >
  >




-- 
Best regards,


WiB



[jQuery] Re: tbody:first-child & thead

2009-02-25 Thread Mauricio (Maujor) Samy Silva
Hi Alex,

1-) Doesn't work because * E F:first-child * pseudo-class selector matches the 
F element that is the first child of the E element ONLY if there isn't another 
element BEFORE the E element within the parent E. See specs at: 
http://www.w3.org/TR/CSS2/selector.html#first-child

 2-) If you have a thead or/and a tbody in your markup, to select the first 
thead use the pseudo-class :eq instead. 

$("#myTable tbody:eq(0) tr").length )

Maurício
  -Mensagem Original- 
  De: Alex Wibowo 
  Para: jquery-en@googlegroups.com 
  Enviada em: quarta-feira, 25 de fevereiro de 2009 08:33
  Assunto: [jQuery] Re: tbody:first-child & thead


  Hi Karl.. thanks for the reply...

  what i actually wanted is to select the first tbody thats why i 
specified tbody:first-child there
  since a table can have multiple tbody... i want to select the first tbody.

  What I didnt understand is about the thead..

  the following works


  
 
  
   
  

  

  $("#myTable  tbody:first-child  tr").length;


  but this doesnt work:



  
 
 
  ...
 


 
  
   
  

  

  $("#myTable  tbody:first-child  tr").length;


  I dont know how  thead causes the second code above not to work...





  On Wed, Feb 25, 2009 at 8:11 PM, Karl Rudd  wrote:


tbody:first-child doesn't select the "first child of the tbody" it
says "select the tbody that is the 'first-child' of it's parent".

So what you are actually wanting to say is:

$("#myTable tbody tr:first-child")

Which is "select the tr that is the first child of tbody"

http://docs.jquery.com/Selectors/firstChild

Karl Rudd


On Wed, Feb 25, 2009 at 8:08 PM, Alex Wibowo  wrote:
> sorry i should say
> "how does that explain the behaviour when there's no thead" (because it
> works when thead doesnt exist)
>
> On Wed, Feb 25, 2009 at 8:06 PM, Alex Wibowo  wrote:
>>
>> how does that explain the behaviour when there's thead then??
>>
>>
>> On Wed, Feb 25, 2009 at 7:47 PM, David Muir  wrote:
>>>
>>> It's because tbody:first-child is already selecting the tr, so you're
>>> effectively doing:
>>> tbody tr tr (where the first tr is the first child of tbody)
>>>
>>> Cheers,
>>> David
>>>
>>>
>>> Alex Wibowo wrote:
>>>>
>>>> Hi all,
>>>>
>>>> I have a code that counts the number of rows in a table...
>>>>
>>>> the table looks like:
>>>>
>>>> 
>>>>  
>>>>   ...
>>>>   
>>>>
>>>>   
>>>>
>>>> 
>>>>
>>>>  
>>>> 
>>>>
>>>>
>>>> and my jquery looks like:
>>>>
>>>> $("#myTable  tbody:first-child  tr").length;
>>>>
>>>> strange enough that always returns 0.
>>>> but if i remove the thead from the table... then it will return the
>>>> correct number of rows..
>>>>
>>>> or alternatively, i can keep the thead, but use the following instead:
>>>>
>>>> $("#myTable  tbody  tr").length;
>>>>
>>>> i.e. without specifying first-child.
>>>>
>>>> Can anyone explain this behaviour?
>>>>
>>>>
>>>>
>>>> THanks a lot!
>>>>
>>>>
>>>>
>>>> --
>>>> Best regards,
>>>>
>>>>
>>>> WiB
>>>>
>>>
>>
>>
>>
>> --
>> Best regards,
>>
>>
>> WiB
>>
>
>
>
> --
> Best regards,
>
>
> WiB
>
>




  -- 
  Best regards,


  WiB



[jQuery] Re: tbody:first-child & thead

2009-02-25 Thread David Muir

Because tbody is no longer the first child.
What you want is tbody:first which will grab the first tbody.

David

Alex Wibowo wrote:

Hi Karl.. thanks for the reply...

what i actually wanted is to select the first tbody thats why 
i specified tbody:first-child there

since a table can have multiple tbody... i want to select the first tbody.

What I didnt understand is about the thead..

the following works


   

 

  


$("#myTable  tbody:first-child  tr").length;


but this doesnt work:


   
   
...
   
  
   

 

  


$("#myTable  tbody:first-child  tr").length;


I dont know how  thead causes the second code above not to work...



On Wed, Feb 25, 2009 at 8:11 PM, Karl Rudd > wrote:



tbody:first-child doesn't select the "first child of the tbody" it
says "select the tbody that is the 'first-child' of it's parent".

So what you are actually wanting to say is:

$("#myTable tbody tr:first-child")

Which is "select the tr that is the first child of tbody"

http://docs.jquery.com/Selectors/firstChild

Karl Rudd

On Wed, Feb 25, 2009 at 8:08 PM, Alex Wibowo mailto:alexwib...@gmail.com>> wrote:
> sorry i should say
> "how does that explain the behaviour when there's no thead"
(because it
> works when thead doesnt exist)
>
> On Wed, Feb 25, 2009 at 8:06 PM, Alex Wibowo
mailto:alexwib...@gmail.com>> wrote:
>>
>> how does that explain the behaviour when there's thead then??
>>
>>
>> On Wed, Feb 25, 2009 at 7:47 PM, David Muir
mailto:davidkm...@gmail.com>> wrote:
>>>
>>> It's because tbody:first-child is already selecting the tr, so
you're
>>> effectively doing:
>>> tbody tr tr (where the first tr is the first child of tbody)
>>>
>>> Cheers,
>>> David
>>>
>>>
>>> Alex Wibowo wrote:

 Hi all,

 I have a code that counts the number of rows in a table...

 the table looks like:

 
  
   ...
   

   

 

  
 


 and my jquery looks like:

 $("#myTable  tbody:first-child  tr").length;

 strange enough that always returns 0.
 but if i remove the thead from the table... then it will
return the
 correct number of rows..

 or alternatively, i can keep the thead, but use the following
instead:

 $("#myTable  tbody  tr").length;

 i.e. without specifying first-child.

 Can anyone explain this behaviour?



 THanks a lot!



 --
 Best regards,


 WiB

>>>
>>
>>
>>
>> --
>> Best regards,
>>
>>
>> WiB
>>
>
>
>
> --
> Best regards,
>
>
> WiB
>
>




--
Best regards,


WiB





[jQuery] Re: tbody:first-child & thead

2009-02-25 Thread Alex Wibowo
Hi Karl.. thanks for the reply...

what i actually wanted is to select the first tbody thats why i
specified tbody:first-child there
since a table can have multiple tbody... i want to select the first tbody.

What I didnt understand is about the thead..

the following works


   

 

  


$("#myTable  tbody:first-child  tr").length;


but this doesnt work:


   
   
...
   
  
   

 

  


$("#myTable  tbody:first-child  tr").length;


I dont know how  thead causes the second code above not to work...



On Wed, Feb 25, 2009 at 8:11 PM, Karl Rudd  wrote:

>
> tbody:first-child doesn't select the "first child of the tbody" it
> says "select the tbody that is the 'first-child' of it's parent".
>
> So what you are actually wanting to say is:
>
> $("#myTable tbody tr:first-child")
>
> Which is "select the tr that is the first child of tbody"
>
> http://docs.jquery.com/Selectors/firstChild
>
> Karl Rudd
>
> On Wed, Feb 25, 2009 at 8:08 PM, Alex Wibowo  wrote:
> > sorry i should say
> > "how does that explain the behaviour when there's no thead" (because it
> > works when thead doesnt exist)
> >
> > On Wed, Feb 25, 2009 at 8:06 PM, Alex Wibowo 
> wrote:
> >>
> >> how does that explain the behaviour when there's thead then??
> >>
> >>
> >> On Wed, Feb 25, 2009 at 7:47 PM, David Muir 
> wrote:
> >>>
> >>> It's because tbody:first-child is already selecting the tr, so you're
> >>> effectively doing:
> >>> tbody tr tr (where the first tr is the first child of tbody)
> >>>
> >>> Cheers,
> >>> David
> >>>
> >>>
> >>> Alex Wibowo wrote:
> 
>  Hi all,
> 
>  I have a code that counts the number of rows in a table...
> 
>  the table looks like:
> 
>  
>   
>    ...
>    
> 
>    
> 
>  
> 
>   
>  
> 
> 
>  and my jquery looks like:
> 
>  $("#myTable  tbody:first-child  tr").length;
> 
>  strange enough that always returns 0.
>  but if i remove the thead from the table... then it will return the
>  correct number of rows..
> 
>  or alternatively, i can keep the thead, but use the following instead:
> 
>  $("#myTable  tbody  tr").length;
> 
>  i.e. without specifying first-child.
> 
>  Can anyone explain this behaviour?
> 
> 
> 
>  THanks a lot!
> 
> 
> 
>  --
>  Best regards,
> 
> 
>  WiB
> 
> >>>
> >>
> >>
> >>
> >> --
> >> Best regards,
> >>
> >>
> >> WiB
> >>
> >
> >
> >
> > --
> > Best regards,
> >
> >
> > WiB
> >
> >
>



-- 
Best regards,


WiB


[jQuery] Re: tbody:first-child & thead

2009-02-25 Thread David Muir


Oops. Got tripped up by this last week too...

David

Karl Rudd wrote:

tbody:first-child doesn't select the "first child of the tbody" it
says "select the tbody that is the 'first-child' of it's parent".

So what you are actually wanting to say is:

$("#myTable tbody tr:first-child")

Which is "select the tr that is the first child of tbody"

http://docs.jquery.com/Selectors/firstChild

Karl Rudd

On Wed, Feb 25, 2009 at 8:08 PM, Alex Wibowo  wrote:
  

sorry i should say
"how does that explain the behaviour when there's no thead" (because it
works when thead doesnt exist)

On Wed, Feb 25, 2009 at 8:06 PM, Alex Wibowo  wrote:


how does that explain the behaviour when there's thead then??


On Wed, Feb 25, 2009 at 7:47 PM, David Muir  wrote:
  

It's because tbody:first-child is already selecting the tr, so you're
effectively doing:
tbody tr tr (where the first tr is the first child of tbody)

Cheers,
David


Alex Wibowo wrote:


Hi all,

I have a code that counts the number of rows in a table...

the table looks like:


 
  ...
  

  
   

   
 



and my jquery looks like:

$("#myTable  tbody:first-child  tr").length;

strange enough that always returns 0.
but if i remove the thead from the table... then it will return the
correct number of rows..

or alternatively, i can keep the thead, but use the following instead:

$("#myTable  tbody  tr").length;

i.e. without specifying first-child.

Can anyone explain this behaviour?



THanks a lot!



--
Best regards,


WiB

  


--
Best regards,


WiB

  


--
Best regards,


WiB







[jQuery] Re: tbody:first-child & thead

2009-02-25 Thread Karl Rudd

tbody:first-child doesn't select the "first child of the tbody" it
says "select the tbody that is the 'first-child' of it's parent".

So what you are actually wanting to say is:

$("#myTable tbody tr:first-child")

Which is "select the tr that is the first child of tbody"

http://docs.jquery.com/Selectors/firstChild

Karl Rudd

On Wed, Feb 25, 2009 at 8:08 PM, Alex Wibowo  wrote:
> sorry i should say
> "how does that explain the behaviour when there's no thead" (because it
> works when thead doesnt exist)
>
> On Wed, Feb 25, 2009 at 8:06 PM, Alex Wibowo  wrote:
>>
>> how does that explain the behaviour when there's thead then??
>>
>>
>> On Wed, Feb 25, 2009 at 7:47 PM, David Muir  wrote:
>>>
>>> It's because tbody:first-child is already selecting the tr, so you're
>>> effectively doing:
>>> tbody tr tr (where the first tr is the first child of tbody)
>>>
>>> Cheers,
>>> David
>>>
>>>
>>> Alex Wibowo wrote:

 Hi all,

 I have a code that counts the number of rows in a table...

 the table looks like:

 
  
   ...
   

   
        
         
        
  
 


 and my jquery looks like:

 $("#myTable  tbody:first-child  tr").length;

 strange enough that always returns 0.
 but if i remove the thead from the table... then it will return the
 correct number of rows..

 or alternatively, i can keep the thead, but use the following instead:

 $("#myTable  tbody  tr").length;

 i.e. without specifying first-child.

 Can anyone explain this behaviour?



 THanks a lot!



 --
 Best regards,


 WiB

>>>
>>
>>
>>
>> --
>> Best regards,
>>
>>
>> WiB
>>
>
>
>
> --
> Best regards,
>
>
> WiB
>
>


[jQuery] Re: tbody:first-child & thead

2009-02-25 Thread Alex Wibowo
sorry i should say
"how does that explain the behaviour when there's no thead" (because it
works when thead doesnt exist)

On Wed, Feb 25, 2009 at 8:06 PM, Alex Wibowo  wrote:

> how does that explain the behaviour when there's thead then??
>
>
>
> On Wed, Feb 25, 2009 at 7:47 PM, David Muir  wrote:
>
>>
>> It's because tbody:first-child is already selecting the tr, so you're
>> effectively doing:
>> tbody tr tr (where the first tr is the first child of tbody)
>>
>> Cheers,
>> David
>>
>>
>>
>> Alex Wibowo wrote:
>>
>>> Hi all,
>>>
>>> I have a code that counts the number of rows in a table...
>>>
>>> the table looks like:
>>>
>>> 
>>>  
>>>   ...
>>>   
>>>
>>>   
>>>
>>> 
>>>
>>>  
>>> 
>>>
>>>
>>> and my jquery looks like:
>>>
>>> $("#myTable  tbody:first-child  tr").length;
>>>
>>> strange enough that always returns 0.
>>> but if i remove the thead from the table... then it will return the
>>> correct number of rows..
>>>
>>> or alternatively, i can keep the thead, but use the following instead:
>>>
>>> $("#myTable  tbody  tr").length;
>>>
>>> i.e. without specifying first-child.
>>>
>>> Can anyone explain this behaviour?
>>>
>>>
>>>
>>> THanks a lot!
>>>
>>>
>>>
>>> --
>>> Best regards,
>>>
>>>
>>> WiB
>>>
>>>
>>
>
>
> --
> Best regards,
>
>
> WiB
>
>


-- 
Best regards,


WiB


[jQuery] Re: tbody:first-child & thead

2009-02-25 Thread Alex Wibowo
how does that explain the behaviour when there's thead then??


On Wed, Feb 25, 2009 at 7:47 PM, David Muir  wrote:

>
> It's because tbody:first-child is already selecting the tr, so you're
> effectively doing:
> tbody tr tr (where the first tr is the first child of tbody)
>
> Cheers,
> David
>
>
>
> Alex Wibowo wrote:
>
>> Hi all,
>>
>> I have a code that counts the number of rows in a table...
>>
>> the table looks like:
>>
>> 
>>  
>>   ...
>>   
>>
>>   
>>
>> 
>>
>>  
>> 
>>
>>
>> and my jquery looks like:
>>
>> $("#myTable  tbody:first-child  tr").length;
>>
>> strange enough that always returns 0.
>> but if i remove the thead from the table... then it will return the
>> correct number of rows..
>>
>> or alternatively, i can keep the thead, but use the following instead:
>>
>> $("#myTable  tbody  tr").length;
>>
>> i.e. without specifying first-child.
>>
>> Can anyone explain this behaviour?
>>
>>
>>
>> THanks a lot!
>>
>>
>>
>> --
>> Best regards,
>>
>>
>> WiB
>>
>>
>


-- 
Best regards,


WiB


[jQuery] Re: tbody:first-child & thead

2009-02-25 Thread David Muir


It's because tbody:first-child is already selecting the tr, so you're 
effectively doing:

tbody tr tr (where the first tr is the first child of tbody)

Cheers,
David


Alex Wibowo wrote:

Hi all,

I have a code that counts the number of rows in a table...

the table looks like:


  
   ...
   

   

 

  



and my jquery looks like:

$("#myTable  tbody:first-child  tr").length;

strange enough that always returns 0.
but if i remove the thead from the table... then it will return the 
correct number of rows..


or alternatively, i can keep the thead, but use the following instead:

$("#myTable  tbody  tr").length;

i.e. without specifying first-child.

Can anyone explain this behaviour?



THanks a lot!



--
Best regards,


WiB