Use appendTo to add element to parent - Javascript jQuery Method and Property

Javascript examples for jQuery Method and Property:append

Description

Use appendTo to add element to parent

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.4.4.min.js"></script> 
  <script type="text/javascript">
    $(window).load(function(){//from   w  ww.  ja v  a  2  s. c  o  m
$("div>img").each(function(){
    $(this).appendTo($(this).parent());
});
    });

      </script> 
 </head> 
 <body> 
  <div class="container"> 
   <img src="http://www.java2s.com/style/demo/InternetExplorer.png"> 
   <p>Hey</p> 
  </div> 
  <div class="container"> 
   <img src="http://www.java2s.com/style/demo/Firefox.png"> 
   <p>Hey</p> 
  </div>  
 </body>
</html>

Related Tutorials