JavaScript Node selectstart Event

Beginner
⏱️ 10 min read
📚 Updated: Jul 2026
🎯 5 Examples
🚀 5 Try-it labs
DOM event

What You’ll Learn

The selectstart event fires when a user starts a new selection. Learn addEventListener vs onselectstart, how preventDefault() blocks the selection, and why MDN marks this event Limited availability—plus how it fits the Selection API next to addEventListener().

01

Kind

DOM event

02

Type

Event

03

Bubbles

Yes

04

Cancelable

Yes

05

Handler

onselectstart

06

Status

Limited availability

Introduction

When someone presses and drags to highlight text, the browser is about to create a new selection range. Right before that change (in the cases the Selection API defines), it fires selectstart.

MDN: if the event is canceled, the selection is not changed. That makes selectstart useful for “do not allow selecting this content” patterns—with the caveat that support is not universal on every mobile browser.

💡
Beginner tip

Prefer addEventListener("selectstart", ...) so you can attach multiple handlers and remove them cleanly. The onselectstart property is fine for quick demos.

Understanding selectstart

Part of the Selection API. It answers: “The user is starting a new selection—should we allow it?”

  • Fires when a user starts a new selection.
  • Cancel with preventDefault() to keep the selection unchanged.
  • Generic Event — no special payload properties beyond a normal Event.
  • Limited availability — not Baseline; test Safari iOS carefully.

📝 Syntax

Use the event name with addEventListener, or set the handler property:

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

onselectstart = (event) => { };

Event type

A generic Event.

Bubbling and cancelable

Per the Selection API, selectstart bubbles and is cancelable. Canceling it means the user agent must not change the selection.

⚖️ selectstart vs select vs selectionchange

Event When it fires Typical use
selectstart User starts a new selection Detect or block selection start
select Selection inside some form controls changes <input> / <textarea> selection
selectionchange Current selection changes React after the selection updates

⚠️ Limited Availability (Not Baseline)

MDN labels selectstart as Limited availability: it is not Baseline because it does not work in some widely used browsers. Desktop Chrome, Firefox, Edge, and Safari generally support it; Safari on iOS is a common gap.

It is still a standard Selection API event—not Deprecated, Experimental, or Non-standard. For “no copy” UX, also consider CSS user-select: none as a complementary approach.

⚡ Quick Reference

Goal Code
Listen on document document.addEventListener("selectstart", fn)
Handler property document.onselectstart = fn
Block selection event.preventDefault()
Scoped listen el.addEventListener("selectstart", fn)
Read selection later document.getSelection()
MDN status Limited availability (not Baseline)

🔍 At a Glance

Four facts to remember about the selectstart event.

Event type
Event

Generic

Cancelable
yes

preventDefault

Bubbles
yes

Selection API

Baseline
no

Limited availability

Examples Gallery

Examples follow MDN Node: selectstart event. Try It Yourself labs let you drag-select text and watch the log. Use View Output for the expected console messages from the sample handlers.

📚 Getting Started

Register handlers the MDN ways.

Example 1 — addEventListener("selectstart")

MDN: listen on document and log when selection starts.

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

// Drag to highlight any text on the page to fire the event.
Try It Yourself

How It Works

Each time the user begins a new selection, the listener runs. Starting another selection later fires it again.

Example 2 — onselectstart Property

MDN’s alternate style using the event handler property.

JavaScript
document.onselectstart = () => {
  console.log("Selection started.");
};

// Note: assigning again replaces the previous onselectstart handler.
Try It Yourself

How It Works

Same event, different registration API. Prefer addEventListener when you need more than one handler.

📈 Cancel, Scope & Selection

Block selection, listen on one element, read the Selection object.

Example 3 — Cancel Selection with preventDefault()

MDN: if the event is canceled, the selection is not changed.

JavaScript
document.addEventListener("selectstart", (event) => {
  event.preventDefault();
  console.log("Selection blocked");
});

// Attempting to drag-select text should not create a highlight
// (where selectstart is supported).
Try It Yourself

How It Works

Because the event is cancelable, preventDefault() tells the browser not to apply the new selection. Pair with CSS user-select for broader coverage.

Example 4 — Listen on One Element Only

Attach to a container so you only react when selection starts inside it (via bubbling).

JavaScript
const box = document.getElementById("protect");

box.addEventListener("selectstart", (event) => {
  console.log("selectstart inside #protect");
  console.log("target:", event.target.nodeName);
});

// Selecting text outside #protect will not hit this listener
// unless the event bubbles through another ancestor you also listen on.
Try It Yourself

How It Works

The event bubbles, so a parent can observe starts that originate on descendant text. Use event.target to see where it began.

Example 5 — After Start, Read getSelection()

Log when selection starts; optionally inspect the Selection on the next tick.

JavaScript
document.addEventListener("selectstart", () => {
  console.log("Selection started");
  // Selection may still be empty/collapsed at the very start;
  // read again after the user finishes dragging if you need the final text.
  requestAnimationFrame(() => {
    const sel = document.getSelection();
    console.log("isCollapsed:", sel ? sel.isCollapsed : null);
  });
});
Try It Yourself

How It Works

selectstart means “beginning,” not “finished highlight.” For the final selected string, also listen to selectionchange or read selection on mouseup.

🚀 Common Use Cases

  • Detecting when a user begins highlighting text for analytics or UI tips.
  • Blocking selection on branded or protected UI regions (where supported).
  • Teaching Selection API basics alongside getSelection().
  • Coordinating custom copy/share toolbars that appear after selection starts.
  • Combining with CSS user-select for defense in depth.

🔧 How It Works

1

User starts selecting

Pointer or keyboard action begins a new range.

Input
2

Browser fires selectstart

A cancelable, bubbling Event is dispatched.

Event
3

Your handler runs

Log, update UI, or call preventDefault().

Handle
4

Selection applies or not

Canceled → unchanged; otherwise selection continues.

📝 Notes

  • MDN: Limited availability (not Baseline)—verify on Safari iOS and other targets.
  • Not Deprecated, Experimental, or Non-standard — no status banner required.
  • Canceling prevents the selection change; it does not replace CSS user-select.
  • Related: addEventListener(), replaceChild(), textContent, Window, JavaScript hub.

Limited Browser Availability

selectstart is a standard Selection API event, but MDN marks it Limited availability (not Baseline). Logos use the shared browser-image-sprite.png sprite from this project. Desktop engines generally support it; Safari on iOS is a notable gap—always verify on real devices.

Limited availability · Not Baseline

Node selectstart

Works on major desktop browsers; missing or unreliable on some mobile browsers (e.g. Safari iOS).

Limited Not Baseline
Google Chrome Supported · Desktop & Android
Full support
Mozilla Firefox Supported since Firefox 52+
Full support
Apple Safari Desktop yes · iOS typically no
Partial
Microsoft Edge Supported · Chromium
Full support
Opera Supported · Modern versions
Full support
Internet Explorer Long-standing support in legacy IE
Full support
selectstart Limited

Bottom line: Cancelable selection-start event; pair with CSS user-select and test Safari iOS.

Conclusion

selectstart lets you react when a user begins a selection—or cancel that start with preventDefault(). Use addEventListener for flexible handlers, remember it is not Baseline everywhere, and combine with CSS when you need stronger “no select” UX.

Continue with addEventListener(), Window, or the JavaScript hub.

💡 Best Practices

✅ Do

  • Prefer addEventListener over a single onselectstart
  • Call preventDefault() only when you truly need to block selection
  • Test on Safari iOS and other mobile browsers
  • Use CSS user-select as a complementary control
  • Read final text via selectionchange or mouseup

❌ Don’t

  • Assume Baseline support on every device
  • Confuse with the form-control select event
  • Expect rich event fields—it is a generic Event
  • Confuse DOM Node with the Node.js runtime
  • Block all selection without an accessibility-friendly reason

Key Takeaways

Knowledge Unlocked

Five things to remember about selectstart

Selection is about to begin—listen or cancel.

5
Core concepts
🚫 02

Cancelable

preventDefault

API
📡 03

Bubbles

parent listen

DOM
⚠️ 04

Not Baseline

limited

Compat
🎨 05

Use CSS too

user-select

UX

❓ Frequently Asked Questions

It is a Selection API event fired when a user starts a new selection (for example dragging to highlight text). If you cancel the event, the selection is not changed.
No. MDN does not mark Node selectstart as Deprecated, Experimental, or Non-standard. It is a standard Selection API event, but MDN labels it Limited availability (not Baseline) because support is missing in some browsers—notably Safari on iOS.
A generic Event. It bubbles and is cancelable (per the Selection API). Call event.preventDefault() to block the new selection.
Use addEventListener("selectstart", handler) or the onselectstart property on document, window, or an element that participates in selection.
The HTML select event (and onselect) typically fires when selection inside an <input> or <textarea> changes. selectstart fires when a new selection begins in the document (often for general text selection), and canceling it prevents that selection from starting.
Can I Use / MDN compatibility data show selectstart unsupported on Safari iOS. Desktop Safari supports it. Always test on your target devices and provide a fallback if blocking selection is critical on iOS.
Did you know?

The Selection API says the user agent must not fire selectstart when it merely sets the selection empty. So clearing a selection is a different story from starting a new one—listen for selectionchange if you need both moments.

Next: JavaScript Window

Explore location and other window-level browser APIs.

Window →

About the author

Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

5 people found this page helpful