Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/457.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/2/jquery/87.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_Jquery - Fatal编程技术网

Javascript jQuery内容分离

Javascript jQuery内容分离,javascript,jquery,Javascript,Jquery,我的结构如下: <div class="cardapio-content"> <h5>Tittle of tab 1</h5> <p>Content of tab 1</p> <h5>Tittle of tab 2</h5> <p>Content of tab 2</p> <h5>Tittle of tab 3</h5>

我的结构如下:

<div class="cardapio-content">
    <h5>Tittle of tab 1</h5>
    <p>Content of tab 1</p>
    <h5>Tittle of tab 2</h5>
    <p>Content of tab 2</p>
    <h5>Tittle of tab 3</h5>
    <p>Content of tab 3</p>
</div>
谢谢。

使用jQuery的.eq来获取所需的元素

jQuery('.cardapio-content h5').each(function(k, v) {
    alert(jQuery('.cardapio-content p').eq(k).html());
})
使用jQuery的.eq获取所需的元素

jQuery('.cardapio-content h5').each(function(k, v) {
    alert(jQuery('.cardapio-content p').eq(k).html());
})
只需使用。下一步:

只需使用。下一步:

仅用于每个函数和选择器,将它们包装在一起:

$('.cardapio-content h5').each(function(){
  $(this).next('p').andSelf().wrapAll('<div class="cardapio-menu" />');
}); 
仅用于每个函数和选择器,将它们包装在一起:

$('.cardapio-content h5').each(function(){
  $(this).next('p').andSelf().wrapAll('<div class="cardapio-menu" />');
}); 

请同时显示预期输出-我无法从您的文字描述中看出。请同时显示预期输出-我无法从您的文字描述中看出。您可以这样做。下一个“p”确保它是。每天学习新内容:-您可以这样做。下一个“p”确保它是。每天学习新内容:-