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.

Example

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:

let container = up.fragment.get('.container')
let 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 all elements matching a selector without further filtering.

Search scope

[root=document]
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.

Type: Element | jQuery | Document
selector
required

The selector to match.

Type: string
[options.layer='current']
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.

Type: string

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.

Type: string | Element | jQuery

Return value

A list of all elements matching the selector.

Returns an empty list if there are no matches.

Type: List<Element>