Edit this page

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

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') // result: true
up.fragment.matches(element, 'span') // result: false
up.fragment.matches(element, ':main') // result: true
up.fragment.matches(element, element) // result: true

Comparison

fragment
required

The element to test.

selector
required

The selector that the fragment should match.

When an Element is passed as this selector argument, this functions tests whether fragment matches a target derived from selector.

stringElement

Layer

[options.layer]
optional

The layer for which to match.

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

Defaults to the layer of fragment.

stringup.Layer
[options.mode]
optional

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

stringup.Layer

Return value

Whether fragment matches the given selector.

boolean