Edit this page

up.fragment up.fragment.all([root], selector, [options])
JavaScript function

Returns all elements matching the given CSS selector, but ignores elements that are being destroyed or that are being removed by a transition.

By default this function only selects elements in the current layer. Pass a { layer }option to match elements in other layers. See up.layer.get() for a list of supported layer values.

Returns an empty list if no element matches these conditions.


To select all elements with the selector .foo on the current layer:

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

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

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

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

var container = up.fragment.get('.container')
var foosInContainer = up.fragment.all(container, '.foo')

Similar features

  • The .up-destroying class is assigned to elements during their removal animation.
  • The up.element.all() function simply returns the all elements matching a selector without further filtering.


[root=document] ElementorjQueryorDocument optional

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

May be omitted to search through all elements in the given layer.

selector string

The selector to match.

[options.layer='current'] string optional

The layer in which to select elements.

See up.layer.get() 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.

[options.origin] stringorElementorjQuery optional

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

Unpoly will prefer to match fragments in the region of the origin element.

The selector argument may refer to the origin as :origin.

Return value

The first matching element, or undefined if no such element matched.