[英]break jquery $('<div>') into separate opening and closing tags
I have several blocks like: 我有几个街区,例如:
<div class="first">...</div>
<div class="second">...</div>
<div class="third">..</div>
I want to wrap all 3 blocks with another div. 我想用另一个div包装所有3个块。 Is there a way to split $('</div>') in two parts: <div> and </div> so I could insertBefore() the opening <div> and insertAfter() the closing </div> I could achieve it simply with html but I can't modify it in this situation
有没有一种方法可以将$('</ div>')分为两部分:<div>和</ div>,所以我可以在开头插入<div>并在结束</ div>插入insert()简单地用html实现它,但是在这种情况下我无法修改它
您可以使用“ wrapAll() ”吗?
$('div').wrapAll('<div class="new" />');
Not sure I'm understanding you correctly, but you should be able to store the elements in variables, and add the new elements to them like this. 不确定我是否正确理解了您,但是您应该能够将元素存储在变量中,并像这样向其中添加新元素。
var el1 = $("div")
var el2 = el.add("div");
var el3 = el2.add("div");
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.