Javascript examples for DOM:Element setAttribute
Element setAttribute() Method - Change class attribute for h1
<!DOCTYPE html> <html> <head> <style> .democlass {// w w w. jav a 2 s .c o m color: red; } </style> </head> <body> <h1>Hello World</h1> <button onclick="myFunction()">Test</button> <script> function myFunction() { var attr = document.createAttribute("class"); attr.value = "democlass"; var h = document.getElementsByTagName("H1")[0]; h.setAttributeNode(attr); } </script> </body> </html>