Remove e Add Atribute

Remove e ADD atributos

by Rapha Souza

HTML

<h1>Hello World</h1>

<p>Click the button to create a "class" attribute with the value "democlass" and insert it to the H1 element above.</p>

<button onclick="myFunction()">Try it</button>
<button onclick="myFunction2()">Try it</button>

CSS

<style>
.democlass {
    color: red;
}
</style>

JavaScript

function myFunction() {
    document.getElementsByTagName("H1")[0].removeAttribute("class"); 
}


function myFunction2() {
    document.getElementsByTagName("H1")[0].setAttribute("class", "democlass"); 
}