swap the order of divs in HTML code - Javascript jQuery Method and Property

Javascript examples for jQuery Method and Property:html

Description

swap the order of divs in HTML code

Demo Code

ResultView the demo in separate window

<html lang="en">
 <head> 
  <title>  faizal</title> 
 </head> /*from w  w w .  j  ava 2  s. c  o m*/
 <body translate="no"> 
  <div class="www"> 
   <div class="div1">
     first div 
   </div> 
   <div class="div2">
     second div 
   </div> 
  </div> 
  <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script> 
  <script>
$('.div2').each(function () {
        $(this).insertBefore($(this).prev('.div1'));
});
    
      </script>  
 </body>
</html>

Related Tutorials