0

I have a bit of a problem and I'm not sure if it's possible with js. Lets say I have a p Element.

<p class="test> text text text </p>

Is it possible that jquery would be able to turn the statement above into this.

<div class="new_created">
<p class="test> text text text </p>
</div>

All on run-time and assuming I can't manually modify it myself. Would appreciate any help on this. Thanks

4

2 回答 2

2

您可以将.wrap()元素与另一个元素一起使用

$('.test').wrap('<div class="new_created"/>')

演示:小提琴

于 2013-08-01T03:05:41.830 回答
0

假设您的 HTML 看起来像这样

<div>
    <p class="test">text text text</p>
</div>

然后,你可以做

$('.test').wrap($('<div class="new_created">'));
于 2013-08-01T03:09:24.127 回答