jQuery Select Event

Beginner
7 min read
Updated: Oct 2026
5 examples
Live preview

What Is the select Event?

The select event fires when the user highlights text inside a text input or textarea. Bind with .on("select", handler) (jQuery 1.7+). Merely placing the cursor does not fire it — at least one character must be selected.

Remember
$("#target").on("select", function () {
  // user highlighted text inside the field
});

$("#other").on("click", function () {
  $("#target").trigger("select"); // runs handlers + selects all text
});

// Not for HTML <select> dropdowns → use change
$("#country").on("change", handler);
NeedUse
React to text highlight.on("select", fn)
Select all + run handlers.trigger("select")
Dropdown value change.on("change", fn)
Get selected sliceselectionStart / selectionEnd on the input
Legacy shorthand.select() ⚠ deprecated 3.3

How to Use select

Bind on a text field, optionally pass data, then trigger when you want to select all text.

  1. Bind with .on("select", handler) on an input or textarea.
  2. Optionally pass eventData: .on("select", data, handler).
  3. Trigger with .trigger("select") to run handlers and select all text.
  4. Read the highlight with selectionStart / selectionEnd (or getSelection()).
  5. Do not use this for HTML <select> dropdowns — use change.
PieceRequired?Role
Text fieldYesinput (text-like) or textarea
handlerFor bindfunction(event) — runs when text is highlighted
eventDataOptionalExtra data available as event.data
HighlightYes (user)At least one character must be selected

Pseudocode

Pseudocode
call input.on("select", handler)
    → store handler on the field

when user highlights text (drag / double-click / Shift+arrow):
    fire "select" on input
    call handler(event)

when user only clicks to place caret:
    select does NOT fire

call input.trigger("select")
    → run bound handlers
    → browser default: select all text in the field

to migrate shorthand:
    .select(fn) → .on("select", fn)
    .select()   → .trigger("select")

Cheat Sheet

Keep these facts handy while wiring text-selection UX.

TopicDetail
Bind$("#el").on("select", handler)
Trigger$("#el").trigger("select") (also selects all text)
Unbind$("#el").off("select" [, handler])
TargetsText input and textarea only
Not forHTML <select> dropdowns → use change
vs changeHighlight vs value change
Since.on("select") 1.7 · .trigger("select") 1.0
Legacy shorthand.select() ⚠ deprecated for binding since 3.3
Read selectionel.selectionStart … el.selectionEnd

Live Preview

Highlight text in the demo field, or run an action to .trigger("select") (selects all).

Click-drag or double-click a word in the field below.

Result
Ready — highlight text or pick an action.

jQuery Examples

Short, copy-ready snippets based on the official jQuery API demos. Open Try It Yourself for a live editor.

Example 1 — Basic .on("select")

Official pattern: run a handler when #target text is highlighted.

jQuery
$("#target").on("select", function () {
  $("#out").text("Handler for select called.");
});
Try It Yourself

How It Works

  1. Bind. .on("select", fn) registers the callback.
  2. Highlight. Drag or double-click to select text.
  3. Fire. The browser sends the select event.
  4. Caret-only. A plain click does not fire the event.

Example 2 — Trigger Select from a Button

Official pattern: #other calls .trigger("select") — handlers run and all text is selected.

jQuery
$("#target").on("select", function () {
  $("#out").text("Select handler ran (user or trigger).");
});

$("#other").on("click", function () {
  $("#target").trigger("select");
});
Try It Yourself

How It Works

  1. Bind. The select handler is ready on #target.
  2. Click. The button runs .trigger("select").
  3. Default. The browser selects all text in the field.
  4. Handler. Bound callbacks run at the same time.

Example 3 — Notice Selection on Any Input

Official demo idea: one handler for every :input text field.

jQuery
$(":input").on("select", function () {
  $("#out").text("Something was selected in " + (this.id || this.name || "a field"));
});
Try It Yourself

How It Works

  1. Select. :input matches form controls on the page.
  2. Bind. Each field gets the same select handler.
  3. Highlight. Selecting text in any of them fires the event.
  4. Identify. this.id / this.name labels the source.

Example 4 — Show Selection Length

Use selectionStart and selectionEnd to measure the highlight.

jQuery
$("#notes").on("select", function () {
  var start = this.selectionStart;
  var end = this.selectionEnd;
  var text = $(this).val().slice(start, end);
  $("#out").text("Selected " + (end - start) + " char(s): " + text);
});
Try It Yourself

How It Works

  1. Event. select fires after the highlight is made.
  2. Range. Read selectionStart and selectionEnd.
  3. Slice. Cut that range from .val().
  4. Show. Display length and the selected string.

Example 5 — eventData for a Mini Toolbar Hint

Pass shared metadata when the user selects text in a notes field.

jQuery
$("#notes").on("select", { tip: "Copy / Bold / Link" }, function (event) {
  $("#out").text("Toolbar: " + event.data.tip);
});
Try It Yourself

How It Works

  1. Data. The object becomes event.data.
  2. Select. Highlighting text fires the handler.
  3. Tip. Read event.data.tip for UI context.
  4. UX. Useful for floating format toolbars.

Edge Cases & Pitfalls

Check these before relying on select handlers in real UIs.

name

Not the HTML <select> element

Dropdown changes use change. The select event is for text highlights only.

caret

Cursor alone does not fire

Clicking to place the insertion point is not enough — highlight at least one character.

trigger

.trigger("select") selects all text

The default action selects the whole field. Expect that side effect in demos and UX.

shorthand

.select(handler) is deprecated

Prefer .on("select", handler). The shorthand bind form is deprecated since jQuery 3.3.

Browser Support

The select event is a standard DOM event on text fields. Bind with .on("select") since jQuery 1.7; .trigger("select") has existed since 1.0. Reading the selected string differs slightly by browser — use selectionStart/selectionEnd or getSelection().

✓ jQuery 1.7+

jQuery select event

Supported in all browsers jQuery targets for input/textarea. Prefer .on('select') / .trigger('select'). Not for HTML select dropdowns.

100% With jQuery loaded
Google Chrome All versions · Desktop & Mobile
Full support
Mozilla Firefox All versions · Desktop & Mobile
Full support
Apple Safari All versions · macOS & iOS
Full support
Microsoft Edge All versions · Chromium & Legacy
Full support
Internet Explorer IE 6+ · Legacy environments
Full support
Opera All modern versions
Full support
select Excellent

Bottom line: Safe for modern and legacy jQuery projects. Remember: text highlight only — use change for dropdowns.

Performance Notes

ApproachCostBest for
Direct .on("select") on known fieldsCheapEditors, copy helpers, toolbars
Reading selectionStart/EndCheapCharacter counts, snippets
Heavy work on every selectExpensiveAvoid — keep handlers light

Select can fire often while users adjust a highlight. Keep callbacks small — update a label or show a toolbar tip.

Key Takeaways

  • Role: react when the user highlights text in an input/textarea.
  • API: .on("select", fn) and .trigger("select").
  • Not dropdowns: HTML <select> uses change.
  • Trigger side effect: .trigger("select") selects all text.

One line: use select for text highlights in inputs/textareas — not for dropdown menus.

Frequently Asked Questions

The select event fires when the user makes a text selection inside an element — by click-dragging or double-clicking to highlight characters. It is limited to text inputs and textareas. Bind with .on("select", handler) since jQuery 1.7. Do not confuse it with the HTML <select> dropdown or the change event.
No. Placing the cursor (insertion point) alone does not trigger select. The user must highlight at least one character — click-drag, double-click a word, or Shift+arrow in supporting browsers.
It runs bound select handlers and also fires the browser default select action — typically selecting all text in the field. That is why the official jQuery demo selects the entire input when you click Trigger.
change fires when the field value changes. select fires when the user highlights existing text. You can select text without changing the value, and you can change a value without selecting text.
Common approaches: for inputs, use element.selectionStart and element.selectionEnd to slice .val(); or use window.getSelection() / document.getSelection().toString(). Browser details differ — many plugins wrap these APIs.
Prefer .on("select", handler) and .trigger("select"). The .select() shorthand binding form is deprecated since jQuery 3.3. See the .select() method tutorial for migration details.

Next: .select() method

Learn the deprecated shorthand for bind/trigger select — and how to migrate it.

.select() tutorial →

About the author

Mari Selvan M P
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.

9 people found this page helpful