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. If the press lands on an element within that handles its own click, like a checkbox, or another script prevented the mousedown event, up:click is emitted on click as usual.

This is useful for listening 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) {
  ...
})

Cancellation

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

Canceling up:click on a hyperlink will prevent 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 event is only emitted for unmodified clicks.

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


Event properties

event.target
required

The clicked element.

Type: Element
event.originalEvent
required

The underlying click or mousedown event.

Type: Event
event.preventDefault()
required

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