Javascript examples for DOM:Element className
Add class with Javascript
<html> <head> <meta name="viewport" content="width=device-width, initial-scale=1"> <style id="compiled-css" type="text/css"> #my/*from w w w. ja v a 2 s . com*/ { width: 100px; height: 100px; border: 1px solid #000; } .class1 { background-color: #0e0e0e; } </style> <script type="text/javascript"> window.onload=function(){ document.getElementById('my').className = "class1"; } </script> </head> <body> <div id="my"></div> </body> </html>