what does this mean: “jQuery('> li', this)”

前端 未结 6 422
慢半拍i
慢半拍i 2021-01-13 01:38

I\'m trying to figure out how this jQuery plugin works: http://codeasily.com/jquery/multi-column-list-with-jquery

In the plugin there is this line at the beginning:<

相关标签:
6条回答
  • 2021-01-13 02:11

    It will look for li element in the immediate children within this element where this can be a jQuery object or DOM element.

    0 讨论(0)
  • 2021-01-13 02:13

    Don't use it. The docs advise that you shouldn't use at as it will be soon deprecated.

    From http://api.jquery.com/child-selector/

    Note: The $("> elem", context) selector will be deprecated in a future release. Its usage is thus discouraged in lieu of using alternative selectors.


    But to answer, it effectively uses the element(s) from which the selector is called as the left hand operand of the child-selector.

    0 讨论(0)
  • 2021-01-13 02:14

    It's the same as $(this).children('li'). It's basically saying "use this as the context for the selector (> li)".

    0 讨论(0)
  • 2021-01-13 02:16

    its jsut like ul > li except that in this case you are replacing the ul part with the current context which is this. So whatever this is in the scope of that call that is the element you are resolving the > li to.

    So for example:

    var ele = $('ul#someId');
    var list = $('> li', ele);
    
    
    var list2 = $('ul#someId > li');
    
    // list is the same as list2
    
    0 讨论(0)
  • 2021-01-13 02:17

    The 2nd parameter to the jQuery function is the context.

    jQuery('> li', this)
    

    Is the same as:

    jQuery(this).find('> li')
    
    0 讨论(0)
  • 2021-01-13 02:31

    The selector is looking for any immediate <li> children in the context of the this DOM element

    0 讨论(0)
提交回复
热议问题