jquery child selector without parent

前端 未结 3 1889
旧巷少年郎
旧巷少年郎 2021-02-14 05:38

I was looking at some code from a tutorial for creating a carousel menu and noticed parent child selectors without the parent. Never seen this before, and confused to what it is

3条回答
  •  甜味超标
    2021-02-14 06:17

    $('> div', this)
    

    The this is important. It's a context parameter that makes the query equal to

    $(this).children('div');
    

    See the documentation for $() for more information; it specifically mentions this:

    Internally, selector context is implemented with the .find() method, so $('span', this) is equivalent to $(this).find('span').

    $(this).find('> div') means "the divs that are children of this, which is equal to $(this).children('div').

提交回复
热议问题