Change color of button after click

Description

A button will be created by the HTML Fragment. After clicking the button, the class “active” gets added and the button toggles its color according to its status.

<div id="parent-div" style="width: 200px; height: 100px;">
<button class="buttonClass" type="button" id='button'>Make me RED</button>
</div>

.buttonClass{
height: 100px;
width: 200px;
}
.buttonClass.active{
background-color: red;
}

var btn = document.getElementById('button');
btn.addEventListener("touchstart",
function(){
btn.classList.add("active");
});

Close Menu
Close Panel