Edit this page

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

This feature is experimental. It may be changed or removed in a future version.

Returns whether the given element matches the given CSS selector or other element.

Other than Element#matches() this function supports non-standard selectors like :main or :layer.

Instead of a selector you may also pass a second element. In that case the function returns whether both elements match the same derived target.

Examples

let element = document.querySelector('div[up-main]')
up.fragment.matches(element, 'div') // => true
up.fragment.matches(element, 'span') // => false
up.fragment.matches(element, ':main') // => true
up.fragment.matches(element, element) // => true

Parameters

fragment Element
selector stringorElement

The selector or element to match.

When an element is passed, returns whether element matches the target derived from selector.

[options.layer] stringorup.Layer optional

The layer for which to match.

Pseudo-selectors like :main may expand to different selectors in different layers.

[options.mode] stringorup.Layer optional

Required if { layer: 'new' } is passed.

Return value

boolean