Javascript examples for DOM:Element className
Add class when element is created
<html> <head> <meta name="viewport" content="width=device-width, initial-scale=1"> <script type="text/javascript"> window.onload=function(){//from w w w .java2s . c o m var divElement = document.createElement('div') divElement.className = 'foo'; divElement.innerHTML = "foo"; document.body.appendChild(divElement); } </script> </head> <body> </body> </html>