Javascript 如何在jQuery中用起始元素和结束元素包装元素?
我有多行交替标记的内容Javascript 如何在jQuery中用起始元素和结束元素包装元素?,javascript,php,jquery,html,css,Javascript,Php,Jquery,Html,Css,我有多行交替标记的内容 <div class="tabs-services"> <div class="et_pb_tab_content"> <img src="image_url" /> <h1>1 Walkthrough</h1> <p>Lorem ipsum <a href="#">Click Here!</a></p>
<div class="tabs-services">
<div class="et_pb_tab_content">
<img src="image_url" />
<h1>1 Walkthrough</h1>
<p>Lorem ipsum <a href="#">Click Here!</a></p>
<h1>1 Walkthrough</h1>
<p>Lorem ipsum <a href="#">Click Here!</a></p>
<img src="image_url" />
<img src="image_url" />
<h1>1 Walkthrough</h1>
<p>Lorem ipsum <a href="#">Click Here!</a></p>
</div>
</div>
1演练
同侧眼睑
1演练
同侧眼睑
1演练
同侧眼睑
我想将每个h1及其直接同级包装成一个div class=“wrap”
因此,输出应该如下所示(我想引出img元素):
1演练
同侧眼睑
2演练
同侧眼睑
3演练
同侧眼睑
到目前为止,我尝试过的代码是,但效果不佳:
$(".tabs-services .et_pb_tab_content h1").each(function() {
$(this).nextUntil("h1").wrap("<div class='a'></div");
});
$(“.tabs services.et_pb_tab_content h1”)。每个(函数(){
$(this).nextUntil(“h1”).wrap(在每个分组上使用wrapAll()
。wrap()
将分别包装集合中的每个元素
$(“.tabs services.et_pb_tab_content h1”)。每个(函数(){
$(this).next().add(this).wrapAll(“
$(".tabs-services .et_pb_tab_content h1").each(function() {
$(this).nextUntil("h1").wrap("<div class='a'></div");
});