Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/369.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/275.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 如何在jQuery中用起始元素和结束元素包装元素?_Javascript_Php_Jquery_Html_Css - Fatal编程技术网

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");
   });