<section class="animate-things-wrapper add-a-class">
<button id="addClass">Add class</button>
<div id="box" class="box">
Hi there
</div>
</section>
<script src="../../js/components/add-a-class.js"></script>
<section class="animate-things-wrapper add-a-class">
<button id="addClass">Add class</button>
<div id="box" class="box">
Hi there
</div>
</section>
<script src="{{ path '/js/components/add-a-class.js' }}"></script>
/* No context defined. */
(function () {
document.addEventListener('DOMContentLoaded', function () {
console.log("Add a class active");
const button = document.querySelector('#addClass');
const box = document.querySelector('#box');
button.addEventListener('click', function() {
box.classList.add('active');
})
});
})();
.add-a-class {
.box {
&.active {
background-color: #ff00ff;
color: #ffffff;
}
}
}
No notes defined.