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

Returns a list of a `root` element's descendants matching the given selector.

If the `root` element itself matches the selector, it is also included in the returned list.

<nav aria-label="Contents">

#### Contents

- [Ignored elements](#ignored-elements)
- [Parameters](#parameters)
- [Return value](#return-value)

</nav>

## Ignored elements {#ignored-elements}

The following elements are ignored, even if they match the selector:

- Elements in a different [layer](https://unpoly.com/api/up.layer.md) than `root`.
- Elements that are being [destroyed](https://unpoly.com/api/up.destroy.md) with an animation.
- Elements that are being removed by a [transition](https://unpoly.com/api/up-transition.md).

To include all elements matching the selector, use [`up.element.subtree()`](https://unpoly.com/api/up.element.subtree.md).

---

## Parameters {#parameters}

### root {#root}

(required)

The root element for the search.

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

### selector {#selector}

(required)

The CSS selector to match.

Type: string

---

## Return value {#return-value}

A list of all matching elements.

Type: [NodeList](https://developer.mozilla.org/en-US/docs/Web/API/NodeList)<[Element](https://developer.mozilla.org/en-US/docs/Web/API/Element)> | [Array](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array)<[Element](https://developer.mozilla.org/en-US/docs/Web/API/Element)>

