跳转到主要内容

Node: selectstart event

{{APIRef("Selection API")}}

The selectstart event of the Selection API is fired when a user starts a new selection.

If the event is canceled, the selection is not changed.

Syntax

Use the event name in {{domxref("EventTarget/addEventListener", "addEventListener()")}}:

addEventListener("selectstart", (event) => { })

Alternatively, assign to the event handler property of the interface:

onselectstart = (event) => { }

Event type

A generic {{domxref("Event")}}.

Examples

// addEventListener version
document.addEventListener("selectstart", () => {
  console.log("Selection started");
});

// onselectstart version (but note that this replaces other event listeners
// added using onselectstart, if any)
document.onselectstart = () => {
  console.log("Selection started.");
};

Specifications

{{Specifications}}

Browser compatibility

{{Compat}}

See also

  • {{domxref("Document/selectionchange_event", "selectionchange")}}