# Check Classes On A DOM Element

You can use the [`classList` property](https://developer.mozilla.org/en-US/docs/Web/API/Element/classList) to check what classes have been assigned to a DOM element.

Assuming the following DOM element:

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

Once you get a handle on that element, using your preferred method (e.g. [`Document.getElementById`](https://developer.mozilla.org/en-US/docs/Web/API/Document/getElementById)), you can start inspecting the class list:

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

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

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

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


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://ploegert.gitbook.io/til/programmy/javascript/check-classes-on-a-dom-element.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
