How to find nested items?

This is how in JS we can find nested table elements:

  <div class="content"> <div class="qtext"></div> <div class="еее"> <div class="еее"> <table class="answer"></table> </div> </div> </div> 

 var $qtext = document.body.getElementsByClassName('qtext'); $table = $qtext[0].parentNode.getElementsByTagName('table')[0]; 

Question: And how can we find similarly in jQuery?

I try this way, but it fails:

 var $qtext2 = $('.qtext'); $qtext2.eq(0).parent().children('table').eq(0); 

    1 answer 1

    getElementsByTagName looks at the entire depth, and the children method only of immediate children.

    If you use the find method, the result will be the same.

    In addition, it is not necessary to write eq(0) in most cases they can be omitted.