---
name: "up.element.toggleClass"
area: "API"
kind: "JavaScript function"
parent: "up.element module"
visibility: "deprecated"
url: "https://unpoly.com/api/up.element.toggleClass"
---
<nav aria-label="Unpoly docs">[All docs](https://unpoly.com/index.md) · [up.element module](https://unpoly.com/api/up.element.md)</nav>

# up.element.toggleClass(element, className, [newPresent])

**This feature has been deprecated**. Use [`Element#classList.toggle(className)`](https://developer.mozilla.org/en-US/docs/Web/API/Element/classList) instead.

Load [`unpoly-migrate.js`](https://unpoly.com/changes/upgrading.md) to polyfill deprecated features.

Adds or removes the given class from the given element.

---

## Parameters {#parameters}

### element {#element}

(required)

The element for which to add or remove the class.

Type: [Element](https://developer.mozilla.org/en-US/docs/Web/API/Element)

### className {#className}

(required)

The class which should be added or removed.

Type: string

### [newPresent] {#newPresent}

(optional)

Pass `true` to add the class to the element or `false` to remove it.

If omitted, the class will be added if missing and removed if present.

Type: Boolean

