Skip to content

Latest commit

 

History

History
29 lines (21 loc) · 719 Bytes

check-classes-on-a-dom-element.md

File metadata and controls

29 lines (21 loc) · 719 Bytes

Check Classes On A DOM Element

You can use the classList property to check what classes have been assigned to a DOM element.

Assuming the following DOM element:

<div id="auth-modal" class="modal hidden">...</div>

Once you get a handle on that element, using your preferred method (e.g. Document.getElementById), you can start inspecting the class list:

> element.classList.contains("modal")
true

> element.classList.contains("hidden")
true

> element.classList.contains("taco")
false

> element.classList.toString()
"modal hidden"