【问题标题】:wrapAll and andSelf not wrapping self elementwrapAll 和 andSelf 不包装 self 元素
【发布时间】:2015-07-14 01:36:43
【问题描述】:

我正在使用下面的代码:

$('.graph-img').each(function(index) {
    $(this).prev('h2,h3,h4,h5,h6,p').prevUntil('.graph-img').andSelf().not('h1').wrapAll("<div class='prevent-break'>");
});

它包装了所有元素,但不包括当前引用的.graph-img。任何想法为什么?

【问题讨论】:

    标签: javascript jquery wrapall


    【解决方案1】:

    andSelf 不添加第一组元素,而是添加前一个元素。

    您可以在此处使用.add(this)

    请注意,andSelf 已被弃用,取而代之的是名称较少误导的 addBack

    【讨论】:

      猜你喜欢
      • 2011-10-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-02-20
      • 2014-03-19
      • 2011-03-24
      相关资源
      最近更新 更多