---
name: "up.layer.current"
area: "API"
kind: "JavaScript property"
parent: "up.layer module"
url: "https://unpoly.com/api/up.layer.current"
---
<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.current

Returns the current layer in the [layer stack](https://unpoly.com/api/up.layer.stack.md).

The _current_ layer is usually the [frontmost layer](https://unpoly.com/api/up.layer.front.md). However, there are some cases where the current layer is a layer in the background:

- While an element in a background layer is being [compiled](https://unpoly.com/learn/enhancing-elements.md).
- While an Unpoly event like [`up:request:loaded`](https://unpoly.com/api/up:request:loaded.md) is being triggered from a background layer.
- While an event listener bound to a background layer using [`up.Layer#on()`](https://unpoly.com/api/up.Layer.prototype.on.md) is being called.

To temporarily change the current layer from your own code, use [`up.Layer#asCurrent()`](https://unpoly.com/api/up.Layer.prototype.asCurrent.md).

## Remembering the current layer {#remembering-the-current-layer}

Most functions in the [`up.layer`](https://unpoly.com/api/up.layer.md) package affect the current layer. For example, [`up.layer.dismiss()`](https://unpoly.com/api/up.layer.dismiss.md) is shorthand for `up.layer.current.dismiss()`.

As described above, `up.layer.current` is set to the correct layer in compilers and most events, even if that layer is not the frontmost layer.

If you have async code, the current layer can change when your callback is called. To address this, you can retrieve the current layer for later reference:

```js
function dismissCurrentLayerIn(seconds) {
  let savedLayer = up.layer.current // returns an up.Layer object
  let dismiss = () => savedLayer.dismiss()
  setTimeout(dismiss, seconds * 1000)
}

dismissCurrentLayerIn(10) //
```

---

## Value {#value}

### current {#current}

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

