Javascript setattribute

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>

Related Sourcecode

More Sourcecode

×
Google login
SignUp with Email
X