---
name: "up.fragment.all"
area: "API"
kind: "JavaScript function"
parent: "up.fragment module"
url: "https://unpoly.com/api/up.fragment.all"
---
<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.all([root], selector, [options])

Returns all elements matching the given CSS 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).

By default this function only selects elements in the [current layer](https://unpoly.com/api/up.layer.current.md). Pass a `{ layer }`option to match elements in other layers. See [`up.layer.get()`](https://unpoly.com/api/up.layer.get.md) for a list of supported layer values.

Returns an empty list if no element matches these conditions.

<nav aria-label="Contents">

#### Contents

- [Example](#example)
- [Similar features](#similar-features)
- [Parameters](#parameters)
- [Return value](#return-value)

</nav>

## Example {#example}

To select all elements with the selector `.foo` on the [current layer](https://unpoly.com/api/up.layer.current.md):

```js
let foos = up.fragment.all('.foo')
```

You may also pass a `{ layer }` option to match elements within another layer:

```js
let foos = up.fragment.all('.foo', { layer: 'any' })
```

To select in the descendants of an element, pass a root element as the first argument:

```js
let container = up.fragment.get('.container')
let foosInContainer = up.fragment.all(container, '.foo')
```

## Similar features {#similar-features}

- The [`.up-destroying`](https://unpoly.com/api/up-destroying.md) class is assigned to elements during their removal animation.
- The [`up.element.all()`](https://unpoly.com/api/up.element.all.md) function simply returns all elements matching a selector without further filtering.

---

## Parameters {#parameters}

### Search scope {#parameters-search-scope}

#### [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 given [layer](#options.layer).

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

#### selector {#selector}

(required)

The selector to match.

Type: string

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

(optional)

The layer in which to select elements.

See [`up.layer.get()`](https://unpoly.com/api/up.layer.get.md) for a list of supported layer values.

If a `root` element was passed as first argument, this option is ignored and the root element's layer is searched.

Type: string

### Origin {#parameters-origin}

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

(optional)

The origin element that triggered this fragment lookup, e.g. a button that was clicked.

The `selector` argument may refer to the origin as [`:origin`](https://unpoly.com/api/origin.md).

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}

A list of all elements matching the selector.

Returns an empty list if there are no matches.

Type: [List](https://unpoly.com/api/List.md)<[Element](https://developer.mozilla.org/en-US/docs/Web/API/Element)>

