Edit this page

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

Returns all elements matching the given 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:

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.

Parameters

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

An second element or selector that can be referenced as & in the first selector:

var input = document.querySelector('input.email') up.fragment.get('fieldset:has(&)', { origin: input }) // returns the <fieldset> containing input

Return value

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

This website uses cookies to improve usability and analyze traffic.
I accept or learn more