Edit this page

up.link up:click
DOM event

A click event that honors the [up-instant] attribute.

This event is generally emitted when an element is clicked. However, for elements with an [up-instant] attribute this event is emitted on mousedown instead.

This is useful to listen to links being activated, without needing to know whether a link is [up-instant].

Example

Assume we have two links, one of which is [up-instant]:

<a href="/one">Link 1</a>
<a href="/two" up-instant>Link 2</a>

The following event listener will be called when either link is activated:

document.addEventListener('up:click', function(event) {
  ...
})

Cancelation

You may cancel an up:click event using event.preventDefault().

Canceling up:click on a hyperlink will prevent any Unpoly from following that link.

The underlying click or mousedown event will also be canceled.

Accessibility

If the user activates an element using their keyboard, the up:click event will be emitted when the key is pressed even if the element has an [up-instant] attribute.

Only unmodified clicks are considered

To prevent overriding native browser behavior, the up:click is only emitted for unmodified clicks.

In particular, it is not emitted when the user holds Shift, CTRL or Meta while clicking. Neither it is emitted when the user clicks with a secondary mouse button.

Properties

event.target Element

The clicked element.

event.originalEvent Event

The underlying click or mousedown event.

event.preventDefault()

Prevents this event and also the original click or mousedown event.