jQuery: Direct child of $(this)

前端 未结 5 1560
温柔的废话
温柔的废话 2021-02-11 20:43

Is it possible to, somehow, select a direct child of $(this)?

I have:

var obj = $(this);  
$(\"ul\", obj).css(\'width\',s*w);

And need

相关标签:
5条回答
  • 2021-02-11 20:50

    The jQuery constructor can take a second parameter which can is used to override the context of the selection.

    $("ul", this);
    

    And if you just want the first I think you could do

    $("ul:first", this)
    
    0 讨论(0)
  • 2021-02-11 20:56

    This works for me ;)

    $('> ul',this)
    
    0 讨论(0)
  • 2021-02-11 21:03

    this may work too (depends on what exact situation are you in maybe)

    $(this).find('>*:eq(0)')
    
    0 讨论(0)
  • 2021-02-11 21:08

    $(this).children('ul') returns a list of direct children.

    0 讨论(0)
  • Try the following:

    $(this).find("> ul")
    
    0 讨论(0)
提交回复
热议问题