开发者

break jquery $('<div>') into separate opening and closing tags

开发者 https://www.devze.com 2023-04-12 14:47 出处:网络
I have several blocks like: <div class=\"first\">...</div> <div class=\"second\">...</div>

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. 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>开发者_如何学JAVA; I could achieve it simply with html but I can't modify it in this situation


Could you use '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");    
0

精彩评论

暂无评论...
验证码 换一张
取 消