Search
How to Cycle Through Classes on an HTML Element
26.1.2022
Say you have three HTML classes, and a DOM element should only have one of them at a time:
<div class="state-1"</div<div class="state-2"</div<div class="state-3"</div
Now your job is to rotate them. That is, cycle through classes …
How to Cycle Through Classes on...
Body Toggle
6.7.2021
I appreciate the clarity of this trick that Mikael Ainalem posted over on Reddit:
It’s a one-liner that toggles the class on the <body> so you can mock up different states and toggle between them on click.
<body onclick="this.classList.toggle("active");"
Could …
The post...
Could Grouping HTML Classes Make Them More Readable?
22.4.2019
You can have multiple classes on an HTML element:
<div class="module p-2"></div>
Nothing incorrect or invalid there at all. It has two classes. In CSS, both of these will apply:
.module { }
.p-2 { }
const div...
Tabs: It’s Complicated™
19.4.2019
I've said before one quick and powerful thing you can learn as a front-end developer just getting starting with JavaScript is changing classes.
const button = document.querySelector(".my-button");
const element = document.querySelector(".content");
button.addEventListener("click", function()...