简体   繁体   English

wrapAll和andSelf不包装self元素

[英]wrapAll and andSelf not wrapping self element

I'm using the code below: 我正在使用以下代码:

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

It's wrapping all the elements, but excluding .graph-img that this currently refers to. 它包装了所有元素,但不包括当前引用的.graph-img Any ideas why? 有什么想法吗?

andSelf doesn't add the first set of elements, but the previous one. andSelf不会添加第一组元素,而是添加一组。

You may use .add(this) instead here. 您可以在此处使用.add(this)

Note that andSelf has been deprecated in favor of addBack whose name is less misleading. 请注意,不赞成使用ANDSelf ,而建议使用名称较少误导的addBack

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM