Changing element places in jQuery - Javascript jQuery Method and Property

Javascript examples for jQuery Method and Property:appendTo

Description

Changing element places in jQuery

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.5.2.js"></script> 
  <script type="text/javascript">
    $(window).load(function(){//from  w  w  w .j  a  v  a  2 s  .c o  m
var first = $("ul li:first");
var last = $("ul li:last");
first.appendTo(first.parent());
last.prependTo(last.parent());
    });

      </script> 
 </head> 
 <body> 
  <ul> 
   <li id="item-1">1</li> 
   <li id="item-2">2</li> 
   <li id="item-3">3</li> 
  </ul>  
 </body>
</html>

Related Tutorials