📝 Edit page
➕ Add page
Class
Setup
const el = document.getElementById("my-el")
Set
el.className = 'abc def open'
View
el.className
// 'abc def open'
el.classList
// [ "abc", "def" ]
Add
You can only add one class at a time like this. No spaces allowed. The class can only be added once and after that will be ignored.
el.classList.add("xyz")
el.className
'abc def xyz'
Remove
el.classList.remove("abc")
Toggle
Add or remove a class, depending on the current state.
el.classList.toggle("abc")