How to wrap an element from a specific element in jQuery? – .wrap()

To wrap an element from a specific element, wrap() method can be used.

$("#divP").wrap("<div id='divScroll' style='height:100px;width:300px;overflow:scroll;'></div>");

Above code will wrap the “divP” with the specified div html tag.

<p id="divP" style="height:300px;width:500px;background:#efefef;">
This is looking nice.
</p>

After wrapping, above code snippet will become

<div id="divScroll" style="height:100px;width:300px;overflow:scroll;">
<p id="divP" style="height:300px;width:500px;background:#efefef;">
This is looking nice.
</p>
</div>

Enjoyed this post? Share it!

 

Leave a comment

Your email address will not be published.