---
name: "up.element.closest"
area: "API"
kind: "JavaScript function"
parent: "up.element module"
visibility: "deprecated"
url: "https://unpoly.com/api/up.element.closest"
---
<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.closest(element, selector)

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

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

Returns the first element that matches the selector by testing the element itself and traversing up through its ancestors in the DOM tree.

---

## Parameters {#parameters}

### element {#element}

(required)

The element on which to start the search.

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

### selector {#selector}

(required)

The CSS selector to match.

Type: string

---

## Return value {#return-value}

element The matching element.

Returns `null` or `undefined` if no element matches.

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

