jQuery Select Event

Beginner
5 min read
Updated: Nov 2026
3 examples
Form Events

Definition

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.

Syntax

Start with these common calls. Keep them short and readable.

jQuery
$("#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);
CallWhat it does
SelectLearn the jQuery select event: bind with .on(\

Load jQuery before your script (CDN or local file), then wrap DOM work in $(function () { ... }) when needed.

Parameters

ParameterDescription
Step 1Bind with .on("select", handler) on an input or textarea.
Step 2Optionally pass eventData: .on("select", data, handler).
Step 3Trigger with .trigger("select") to run handlers and select all text.

Return Value

Return ValueDescription
jQuery objectMost setters and traversing helpers return the jQuery collection so you can chain more methods.
Value / undefinedGetters usually return a value from the first matched element, or undefined when nothing applies.

jQuery Examples

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.

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.

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.

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() Method tutorial →

CODETOFUN NEWS

Stay Ahead in Tech

Get the latest IT news, programming updates, and technology trends directly on your phone.

Your daily dose of tech, straight to your feed.

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