How to use jQuery.wrapAll() method in jQuery?

jQueryWeb DevelopmentFront End Technology

The wrapAll() method wraps all the elements in the matched set into a single wrapper element.

Here is the description of all the parameters used by this method −

  • elem − A DOM element that will be wrapped around the target.

Example

You can try to run the following code to learn how to use jQuery.wrapAll() method in jQuery −

Live Demo

<html>
   <head>
      <title>jQuery wrapAll() method</title>
      <script src = "https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
      <script>
         $(document).ready(function() {
           $('ul.myclass > li:lt(2)').wrapAll('<div class="demo"></div>')
         });
      </script>

      <style>
         .demo {
            border: 3px dashed blue;
            margin: 5px;
         }      
      </style>

   </head>
   <body>

      <ul class="myclass">
         <li>India</li>
         <li>US</li>
         <li>UK</li>
         <li>Australia</li>
         <li>Bangladesh</li>
      </ul>
   </body>
</html>
raja
Published on 19-Dec-2017 08:51:42

Advertisements