---
name: "up.element.toggle"
area: "API"
kind: "JavaScript function"
parent: "up.element module"
url: "https://unpoly.com/api/up.element.toggle"
---
<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.toggle(element, [newVisible])

Changes whether the given element is [shown](https://unpoly.com/api/up.element.show.md) or [hidden](https://unpoly.com/api/up.element.hide.md).

---

## Parameters {#parameters}

### element {#element}

(required)

The element to toggle.

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

### [newVisible] {#newVisible}

(optional)

Pass `true` to show the element or `false` to hide it.

If omitted, the element will be hidden if shown and shown if hidden.

Type: boolean

