const el = document.getElementById("item");
el.className = el.className === "active" ? "inactive" : "active";Element: className property / notebook
Element: className property
Runnable notebook: every JavaScript, HTML and CSS example on this page executes in a sandboxed local frame. Nothing leaves the browser.
elm.setAttribute("class", "my-class");
const myClass = elm.getAttribute("class");