how to limit the jquery search scope

后端 未结 6 2320
别那么骄傲
别那么骄傲 2020-12-06 16:19

It looks like JQuery does the search in the current document when using a selector.

How to search for an element only inside a div

6条回答
  •  我在风中等你
    2020-12-06 16:46

    Old question, but everyone seems to have missed the scoped jQuery selector (using the scope you desired, i.e. your div selector, as the second parameter)

    e.g. use

    var $matches = $('.adiv', '#mydiv');
    

    This is a shorter equivalent of:

    var $matches = $('#mydiv').find('.adiv');
    

提交回复
热议问题