jQuery .prepend() usage - Javascript jQuery Method and Property

Javascript examples for jQuery Method and Property:prepend

Description

jQuery .prepend() usage

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(){/*ww w .  j ava  2  s  . c o  m*/
var myString = '<div class="lorem">LOREM<div id="temp" class="ipsum">IPSUM</div></div>';
$('a').click(function() {
    $('#mydiv').prepend(myString);
});
    });

      </script> 
 </head> 
 <body> 
  <a href="#">Insert</a> 
  <div id="mydiv"></div>  
 </body>
</html>

Related Tutorials