move lists item inside <UL> - Javascript DOM HTML Element

Javascript examples for DOM HTML Element:Ul

Description

move lists item inside <UL>

Demo Code

ResultView the demo in separate window

<html>
   <head> 
      <title>a/21589970/1636522</title> 
      <meta name="viewport" content="width=device-width, initial-scale=1"> 
   </head> 
   <body> 
      <ul> 
         <li id="li1">1</li> 
         <li id="li2">2</li> 
         <li id="li3">3</li> 
      </ul> 
      <script type="text/javascript">
var list = document.getElementsByTagName('ul')[0],
    items = list.getElementsByTagName('li'),
    i = items.length;
while (i--) /*from   w w  w.  ja  v a2  s  . co m*/
   list.appendChild(items[i]);

      </script>  
   </body>
</html>

Related Tutorials