开发者

Filter <p> within a div and wrap all

开发者 https://www.devze.com 2023-01-12 08:37 出处:网络
I\'m trying to wrap all <p> from a div in a sub-div; the number开发者_如何学Gos of <p> is not constant.

I'm trying to wrap all <p> from a div in a sub-div; the number开发者_如何学Gos of <p> is not constant.

<div id="page">
  <p>text</p>
  <p>text</p>
  <p>text</p>
</div>

Trying to obtain:

<div id="page">
  <div>
    <p>text</p>
    <p>text</p>
    <p>text</p>
  </div>
</div>

Using:

<script>
 jQuery('#page').filter('p').wrapAll('<div></div>');
</script>

And it's not working.


You can do it using .wrapAll() like this:

jQuery('#page p').wrapAll('<div></div>');

Or using .wrapInner() like this:

jQuery('#page').wrapInner('<div></div>');
0

精彩评论

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