【问题标题】:How to select $(this) AND $(this) > child with jQuery?如何使用 jQuery 选择 $(this) AND $(this) > child?
【发布时间】:2012-08-18 22:34:07
【问题描述】:

无法完全弄清楚这一点。如果我使用:

$('> .someClass', this);

它将选择this > .someClass,但我想选择this AND this > child

试过

  $(this+'> .someClass', this);
//AND
 var currentEl = $(this);
  $(currentEl, currentEl+'> .someClass')

任何帮助将不胜感激。

【问题讨论】:

    标签: jquery jquery-selectors this css-selectors parent-child


    【解决方案1】:

    使用andSelf()

    $(this).find('> .someclass').andSelf();
    

    andSelf() documentation

    【讨论】:

      【解决方案2】:

      您可以使用.andSelf() 函数将this 添加到匹配元素的集合中,如下所示:

      $(this).find('> .someclass').andSelf();
      

      【讨论】:

        猜你喜欢
        • 2011-11-08
        • 2011-01-28
        • 1970-01-01
        • 2010-09-19
        • 2010-10-24
        • 1970-01-01
        • 1970-01-01
        • 2011-07-19
        • 2023-03-27
        相关资源
        最近更新 更多