Did I understand correctly that in the code below, we perform a resource-intensive operation to access the DOM only once, and then we work with jQuery objects with good performance?

 <ul class="someClass"> <li class="subclass1"></li> <li class="subclass2"></li> </ul> <ul class="someClass"> <li class="subclass1"></li> <li class="subclass2"></li> </ul> var elementsSet = $('.someClass'); var elementsSubset1 = elementsSet.find('.subclass1') var elementsSubset2 = elementsSet.find('.subclass2') 

    1 answer 1

    With the advent of the native querySelectorAll method in browsers, this is actually not so important. jQuery no longer needs to bypass the tree by itself - it delegates this to highly optimized browser algorithms.

    The only thing when using the selector with id is better to use find:

     // будет использоваться querySelectorAll по всему документу $('#myid .myclass') // будет использоваться очень быстрый метод // getElementById, а затем querySelectorAll по меньшему дереву $('#myid').find('.myclass') 
    • Thank you for your reply! It's great that modern developers of modern browsers are working on the problem of slowness in accessing the DOM. Soon the old browsers would have sunk into oblivion :) - Gleb