How to add class to element in JavaScript

DOM
By Jad Joubran · 
Last updated Feb 26, 2024
<div id="box"></div>
const element = document.querySelector("#box");

// Note: only class name, without the '.'
element.classList.add("class-name");