MDN self-hosted library · e01.org

Element: className property

Runnable notebook: every JavaScript, HTML and CSS example on this page executes in a sandboxed local frame. Nothing leaves the browser.

js
const el = document.getElementById("item");
el.className = el.className === "active" ? "inactive" : "active";
js
elm.setAttribute("class", "my-class");
const myClass = elm.getAttribute("class");