Wrap li into another li - Javascript jQuery Method and Property

Javascript examples for jQuery Method and Property:wrap

Description

Wrap li into another li

Demo Code

ResultView the demo in separate window

<html>
   <head> 
      <meta name="viewport" content="width=device-width, initial-scale=1"> 
      <script type="text/javascript" src="https://code.jquery.com/jquery-1.9.1.js"></script> 
      <script type="text/javascript">
    $(function(){/*from  ww  w .  j  a va  2  s .  c o m*/
$('ul li:not(:first)').wrapAll('<li><ul></ul></li>');
    });

      </script> 
   </head> 
   <body> 
      <ul> 
         <li>1</li> 
         <li>2</li> 
         <li>3</li> 
         <li>4</li> 
      </ul>  
   </body>
</html>

Related Tutorials