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

# up.layer.get([value])

Returns an [`up.Layer`](https://unpoly.com/api/up.Layer.md) object for the given element or [layer option](https://unpoly.com/learn/targeting-other-layers.md).

<nav aria-label="Contents">

#### Contents

- [Looking up the layer of an element](#looking-up-the-layer-of-an-element)
- [Getting the nth layer](#getting-the-nth-layer)
- [Resolving a layer option](#resolving-a-layer-option)
- [Existing `up.Layer` objects are returned](#existing-uplayer-objects-are-returned)
- [Missing values return the current layer](#missing-values-return-the-current-layer)
- [Parameters](#parameters)
- [Return value](#return-value)

</nav>

## Looking up the layer of an element {#looking-up-the-layer-of-an-element}

Passing an element will return the layer containing that element:

```js
let element = document.querySelector(...)
up.layer.get(element) // returns the element's layer
```

If the given element is detached or part of a closing overlay, `undefined` is returned.

## Getting the nth layer {#getting-the-nth-layer}

Pass a number to return the [`up.Layer`](https://unpoly.com/api/up.Layer.md) object at that index:

```js
up.layer.get(0) // returns the root layer
up.layer.get(1) // returns the first overlay
```

## Resolving a layer option {#resolving-a-layer-option}

Pass any [layer option](https://unpoly.com/learn/targeting-other-layers.md) to return the [`up.Layer`](https://unpoly.com/api/up.Layer.md) object of the first layer matching that option:

```js
up.layer.get('front') // returns the front layer
```

To look up one of multiple layer options, separate the values using a comma:

```js
// returns the parent layer, or the root if we're already on root:
up.layer.get('parent, root')
```

## Existing `up.Layer` objects are returned {#existing-uplayer-objects-are-returned}

Passing an existing [`up.Layer`](https://unpoly.com/api/up.Layer.md) object will return it unchanged:

```js
let layer = up.layer.root
up.layer.get(layer) // returns the given layer
```

## Missing values return the current layer {#missing-values-return-the-current-layer}

Passing `null` or `undefined` will return the [current layer](https://unpoly.com/api/up.layer.current.md):

```js
up.layer.get(undefined) // returns the current layer
```

---

## Parameters {#parameters}

### [value='current'] {#value}

(optional)

The [layer option](https://unpoly.com/learn/targeting-other-layers.md) to look up.

Type: string | [up.Layer](https://unpoly.com/api/up.Layer.md) | number

---

## Return value {#return-value}

The layer matching the given option.

If no layer matches, `undefined` is returned.

Type: [up.Layer](https://unpoly.com/api/up.Layer.md) | undefined

