Inserting into newly created elements - Javascript jQuery Method and Property

Javascript examples for jQuery Method and Property:append

Description

Inserting into newly created elements

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.2.js"></script> 
  <script type="text/javascript">
    $(window).load(function(){/*  w  ww. j ava 2  s.c  om*/
var elementToAdd = $('<h3>').html('header');
var p = $('<p>').html('hello world');
$('div#content').append(elementToAdd);
elementToAdd.after(p);
    });

      </script> 
 </head> 
 <body> 
  <div id="content"> 
  </div>  
 </body>
</html>

Related Tutorials