JSFiddle - React, Tailwind, and code Playground

by DiceMasters

HTML

<div class="block"></div>
<div class="block"></div>
<div class="block"></div>
<div class="neblock"></div>

<button id="go">Go</button>

CSS

.block, .neblock {
	width: 50px;
	height: 50px;
	background-color: red;
	margin: 10px;
}

.neblock {
	background-color: gray;
}

.newclass {
	background-color: blue !important;
}

JavaScript

document.getElementById('go').addEventListener('click', function() {
	let arr = document.getElementsByClassName('block')
	
	for (item of arr) {
		item.classList.add('newclass')
	}
})