Add a class to an element created with javascript - Javascript jQuery Method and Property

Javascript examples for jQuery Method and Property:append

Description

Add a class to an element created with javascript

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.9.1.js"></script> 
  <style id="compiled-css" type="text/css">
.your-class {/*from www . java  2  s .c  o m*/
   color: orange;
}
      </style> 
  <script type="text/javascript">
    $(window).load(function(){
$(".an-element").append("<div class='your-class'>Test</div>");
    });

      </script> 
 </head> 
 <body> 
  <div class="an-element"></div>  
 </body>
</html>

Related Tutorials