jQuery > Manipulations methods

.wrap() - Wrap a specific element in jQuery

How to wrap an element from a specific element in jQuery?


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

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

Above code will wrap the element whose id is “divP” with the specified div html tag (passed in .wrap method). So if the "divP" element looks like below

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

After executing first code snippet, the "divP" 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>
 Views: 865 | Post Order: 59



Write for us