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

# up.fragment.first([root], selector, [options])

**This feature has been deprecated**. Use [`up.fragment.get()`](https://unpoly.com/api/up.fragment.get.md) instead.

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

Returns the first element matching the given selector, but ignores elements that are being [destroyed](https://unpoly.com/api/up.destroy.md) or that are being removed by a [transition](https://unpoly.com/api/up.morph.md).

Returns `undefined` if no element matches these conditions.

---

## Parameters {#parameters}

### [root=document] {#root}

(optional)

The root element for the search. Only the root's descendants will be matched.

May be omitted to search through all elements in the current `document`.

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

### selector {#selector}

(required)

The selector to match

Type: string

### [options.layer='current'] {#options.layer}

(optional)

The layer in which to find the element.

See [Targeting other layers](https://unpoly.com/learn/targeting-other-layers.md).

Type: string

### [options.origin] {#options.origin}

(optional)

A second element or selector that can be referenced as [`:origin`](https://unpoly.com/api/origin.md) in the first selector.

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

---

## Return value {#return-value}

The first element that is not being destroyed, or `undefined` if no such element was found.

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

