<html>
<head>
<style type="text/css">
.democlass{
color:red;
}
</style>
</head>
<body>
<h1>Hello World</h1>
<p id="demo">Click the button to set the class attribute node of the header above.</p>
<button onclick="myFunction()">Try it</button>
<script>
function myFunction()
{
var atr=document.createAttribute("class");
atr.nodeValue="democlass";
var h=document.getElementsByTagName("H1")[0];
h.setAttributeNode(atr);
};
</script>
</body>
</html>