Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

I need a better jQuery selector to cut down on children() calls

Currently I am using $('table').children('tfoot').children('tr').children('td');

to get the only td in the tfoot.

I dont like using .children() 3 times,

Is there a better way?


Edit
Slight correction The selector is actually
var table = this;
$(table).children('tfoot').children('tr').children('td');

as this is inside a jquery plugin.

like image 734
Hailwood Avatar asked Dec 21 '22 21:12

Hailwood


1 Answers

$('table > tfoot > tr > td')

children() searches in immediate children, so to replicate this, I used the direct descendant selector (>).

Update

From your update, you could do...

$(table).find(' > tfoot > tr > td')

or you could replace table with this.

I'm glad you are thinking of the children.

like image 150
alex Avatar answered Dec 24 '22 09:12

alex