Search code examples
javascriptjqueryjquery-selectorsdom-traversal

jQuery - strict children hierachy selection


What would the equivalent of the following jQuery selector:

$('table.special > thead > tr')

be if I had $('table.special') as a $table argument in function to start with?

(something of the form $table.(...) but equivalent to the first mentioned selector)


Note: $table.filter('thead > tr') is not what I want, as it also selects thead element of nested tables, and $table.filter('> thead > tr') doesn't work and neither $table.children('thead > tr')...


Solution

  • This is how it can be done:

    $table.children("thead").children("tr");
    

    As well as:

    $table.find("> thead > tr");
    // or
    $("> thead > tr", $table);
    

    but for some reasons this type of selector is deprecated now.