Edit this page

up.fragment up.fragment.toTarget(element, [options])
JavaScript function

Derives a CSS selector that matches the given element as good as possible.

If no target can be derived and verified, an error up.CannotTarget is thrown.

Example

element = up.element.createFromHTML('<span class="klass">...</span>')
selector = up.fragment.toTarget(element) // returns '.klass'

Parameters

element Element|string

The element for which to create a selector.

When a string is given, it is returned unchanged.

[options.verify] Element optional

Whether to verify that the derived selector matches the given element.

Defaults to up.fragment.config.verifyDerivedTarget.

[options.strong=false] Element optional experimental

Whether to provide a more unique selector by only considering the element's [id] and [up-id] attributes.

Weaker target derivers, like the element's class, are not considered in strong mode. The element's tag name is only considered for singleton elements like <html> or <body>.

[options.origin] Element optional