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

Returns the native [Element](https://developer.mozilla.org/en-US/docs/Web/API/Element) for the given value.

This function is not aware of [layers](https://unpoly.com/api/up.layer.md) or [elements being destroyed](https://unpoly.com/api/up-destroying.md) and does not support non-standard selectors like [`:main`](https://unpoly.com/api/main.md). For this, use [`up.fragment.get()`](https://unpoly.com/api/up.fragment.get.md).

<nav aria-label="Contents">

#### Contents

- [Casting rules](#casting-rules)
- [Example](#example)
- [Parameters](#parameters)
- [Return value](#return-value)

</nav>

## Casting rules {#casting-rules}

- If given an element, returns that element.
- If given a CSS selector string, returns the first element matching that selector.
- If given a jQuery collection, returns the first element in the collection. Throws an error if the collection contains more than one element.
- If given any other argument (`undefined`, `null`, `document`, `window`…), returns the argument unchanged.

## Example {#example}

Passing a CSS selector will return the first matching element:

```js
up.element.get('.foo') // returns the first matching element
```

---

## Parameters {#parameters}

### [parent=document] {#parent}

(optional)

The parent element whose descendants to search if `value` is a CSS selector string.

If omitted, all elements in the `document` will be searched.

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

### value {#value}

(required)

The value to look up.

Type: [Element](https://developer.mozilla.org/en-US/docs/Web/API/Element) | [jQuery](https://learn.jquery.com/using-jquery-core/jquery-object/) | string

---

## Return value {#return-value}

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

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

