Javascript setAttribute() method
<h2 align="center">Javascript setattribute</h2>
<style>
.demo{
color: red;
}
</style>
<p id="p">This is p tag.</p>
<button onclick="setAttr()">Set attribute</button>
<script>
function setAttr() {
document.getElementById("p").setAttribute("class", "demo");
}
</script>