HTML Dodaj klasę
//Use element.classList.add to add a class:
let element = document.getElementById("div1");
element.classList.add("otherclass");
Julie Bodette
//Use element.classList.add to add a class:
let element = document.getElementById("div1");
element.classList.add("otherclass");
var someElement= document.getElementById("myElement");
someElement.className += " newclass";//add "newclass" to element (space in front is important)
<script type="text/javascript">
function changeClass(){
// Code examples from above
}
window.onload = function(){
document.getElementById("MyElement").addEventListener( 'click', changeClass);
}
</script>
...
<button id="MyElement">My Button</button>