Patrick Jeon
Patrick Jeon

Reputation: 1824

jquery select child elements

I'm very new to jQuery.

I wrote this code to select child TD elements.

$(this)
    .children("div.tablescroll_wrapper")
    .children("table.tablescroll_body")
    .children("tbody")
    .children("tr.first")
    .children()

It works fine but looks bad, Is there a better way to do this?

Sorry for my low level English and thank you

Upvotes: 2

Views: 3033

Answers (3)

Th0rndike
Th0rndike

Reputation: 3436

you don't have to navigate the entire tree. Just setting an id to the table or selecting tr directly will work:

   $(this).find('tr:first').children();

is good enough. Otherwise, select the table with the id of the table:

Upvotes: 0

thecodeparadox
thecodeparadox

Reputation: 87083

$('div.tablescroll_wrapper > table.tablescroll_body > tr.first', this).children();

or

$('div.tablescroll_wrapper > table.tablescroll_body > tr.first > *', this);

Upvotes: 0

Prasenjit Kumar Nag
Prasenjit Kumar Nag

Reputation: 13461

I am not sure about your html structure, but what you are trying to achieve can be achieved with,

$(this).find("div.tablescroll_wrapper tr.first").children();

Upvotes: 5

Related Questions