I am trying to find all tr elements inside a table element. The table element it self has other table elements nested inside its rows. So when I do the following:
$(tbl).find('tr').hover(...);
…it picks up tr elements inside the nested table elements also. I just want the immediate tr elements of the table element I am trying to query.
$(tbl).find('>tr').hover(...); didn’t work for me!
ps: tbl is a table element, not a string
Read full answer, please.
will give you
tbodyand alsotheadif it exists.So if you want immediate tr, you will need to try this.
$(tbl).children(‘tbody’).children(‘tr’)
Don’t forget to consider
tbodywhile fetching children of atable, as in Firefox a direct call to children like$(tbl).children()returnstbodyand nottr, even if its not in your markup. Complex but useful.Happy Coding.