How to prohibit the use of jQuery Selector nested elements?

I am new to jQuery, so hopefully there is a simple answer to this question.

I have an html similar to:

<table id="dataTable"> <tr> <!-- I want this row --> <td>...</td> <tr> <tr> <td> <table> <tr> <!-- I do not want this row --> <td>...</td> </tr> </table> </td> <tr> </table> 

I am using jQuery similar to this:

 $("#dataTable tr").length; 

I expect the length to be 2, but 3 is returned (includes <tr> in the nested table). My question is: How to prevent the 3rd <tr> from choosing?

I know that I could add the ignorethisrow class to the last line and exclude this from my results, but I would prefer the option that allows me to control the depth that the selector searches for.

+4
source share
1 answer

I believe the syntax is:

 $("#dataTable > tr").length 

means "just tr at the next level."

+15
source

All Articles