Assigning IDs to several child elements - Javascript jQuery Method and Property

Javascript examples for jQuery Method and Property:append

Description

Assigning IDs to several child 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.11.0.js"></script> 
  <script type="text/javascript">
    $(window).load(function(){//www  .j  av  a 2s .  com
$("#wrapper").append(
    $("<div>").attr("id", "main-div")
        .append($("<button>")
               .text("X")
               .attr("id", "myButton")))
    });

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

Related Tutorials