jQuery .select() Method

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

What Is .select()?

.select() is jQuery’s legacy shorthand for binding or triggering the select event — when the user highlights text inside an input or textarea. Binding is deprecated since 3.3; modern code uses .on("select") / .trigger("select"). It is not the HTML <select> dropdown.

Remember
// Legacy (still works; bind form deprecated since 3.3)
$("#target").select(function () {
  // user highlighted text inside the field
});

// Modern replacements
$("#target").on("select", handler);     // bind
$("#target").trigger("select");         // fire + select all text

// Not for HTML <select> dropdowns → use change
$("#country").on("change", handler);
NeedUse
New code (bind).on("select", fn)
New code (trigger).trigger("select")
Legacy bind.select(fn) ⚠ deprecated 3.3
Legacy trigger.select() (prefer .trigger)
Dropdown change.on("change", fn)

How to Use .select()

Recognize the legacy API in old code, then migrate to .on() / .trigger().

  1. Bind with .select(handler) (legacy) or .on("select", handler) (preferred).
  2. Optionally pass eventData: .select(data, handler) → .on("select", data, handler).
  3. Trigger with no-arg .select() (legacy) or .trigger("select") (preferred) — selects all text.
  4. Use only on text input / textarea — not HTML <select>.
  5. For dynamic fields, use delegated .on("select", selector, fn) — not .select().
PieceRequired?Role
handlerFor bind formfunction(event) — runs when text is highlighted
eventDataOptional (1.4.3+)Extra data available as event.data
No-arg callFor triggerFires select + selects all text
Text fieldYesinput (text-like) or textarea

Pseudocode

Pseudocode
// Legacy
call input.select(handler)
    → bind "select" on input

when user highlights text:
    fire "select" on input
    call handler(event)

call input.select()
    → trigger "select" (handlers + select all text)

// Modern
call input.on("select", handler)
call input.trigger("select")

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

Cheat Sheet

Quick map from the shorthand to modern APIs.

TopicDetail
Legacy bind$("#el").select(handler) ⚠ deprecated 3.3
Modern bind$("#el").on("select", handler)
Legacy trigger$("#el").select()
Modern trigger$("#el").trigger("select")
Unbind$("#el").off("select" [, handler])
Since / status1.0 · eventData 1.4.3 · bind deprecated 3.3
TargetsText input and textarea only
Not forHTML <select> → use change
DelegationNot via .select() — use .on("select", "input", fn)

Live Preview

Highlight text in the demo field, or run an action with legacy .select() (still available in jQuery 3.x).

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. Prefer .on("select") for new projects; these demos show the legacy API you will still meet in older code.

Example 1 — Basic .select(handler)

Legacy bind: run a handler when #target text is highlighted.

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

How It Works

  1. Bind. .select(fn) registers the callback (deprecated).
  2. Highlight. Drag or double-click to select text.
  3. Fire. The browser sends the select event.
  4. Prefer. New code should use .on("select", fn).

Example 2 — .select(eventData, handler)

Pass metadata (since 1.4.3). Modern form: .on("select", data, fn).

jQuery
$("#notes").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. Migrate. Use .on("select", data, fn) in new code.

Example 3 — No-Arg .select() Trigger

No arguments means trigger — same as .trigger("select") (selects all text).

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

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

How It Works

  1. Bind. A select handler is ready on #target.
  2. Click. The button calls no-arg .select().
  3. Default. The browser selects all text in the field.
  4. Prefer. New code should use .trigger("select").

Example 4 — Migrate to .on("select")

Side-by-side rename — same behavior, modern API.

jQuery
// Before (deprecated bind)
$("#target").select(function () {
  $("#out").text("legacy .select(fn)");
});

// After (preferred)
$("#target").on("select", function () {
  $("#out").text("modern .on(\"select\", fn)");
});

// Trigger: .select() → .trigger("select")
Try It Yourself

How It Works

  1. Find. Search legacy code for .select(.
  2. Rename bind. .select(fn) → .on("select", fn).
  3. Rename trigger. .select() → .trigger("select").
  4. Test. Highlight and trigger both still work the same.

Example 5 — Select-All Button (Modern Trigger)

Common UX: a button selects all text. Prefer .trigger("select").

jQuery
$("#code").on("select", function () {
  $("#out").text("All or part of the code is selected.");
});

$("#select-all").on("click", function () {
  $("#code").trigger("select"); // modern; was .select()
});
Try It Yourself

How It Works

  1. Bind. Modern .on("select") listens for highlights.
  2. Click. The button calls .trigger("select").
  3. Default. The browser selects the whole field.
  4. Legacy. Old code may still say .select() with no args.

Edge Cases & Pitfalls

Check these before keeping or writing .select() calls.

deprecated

Bind form is deprecated since 3.3

Prefer .on("select", handler). The shorthand still works in jQuery 3.x for legacy code.

name

Not the HTML <select> element

Dropdown changes use change. .select() is for text highlights only.

trigger

No-arg .select() selects all text

Same as .trigger("select") — expect the whole field to become selected.

delegation

No event delegation via shorthand

Use .on("select", "input", fn) on a parent for dynamically added fields.

Browser Support

The .select() shorthand has existed since jQuery 1.0 (eventData since 1.4.3). Binding is deprecated since 3.3 but still present in jQuery 3.x. Prefer .on("select") / .trigger("select") for new code.

✓ Deprecated 3.3+

jQuery .select() shorthand

Works wherever jQuery runs for input/textarea. Binding deprecated since 3.3 — migrate to .on('select') / .trigger('select'). Not for HTML select dropdowns.

Legacy OK Prefer .on() / .trigger()
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() Deprecated bind

Bottom line: Safe to read in old codebases. For new work, use the select event API with .on() and .trigger().

Performance Notes

ApproachCostBest for
.select(fn) / .on("select", fn)Same costKnown text fields
No-arg .select() / .trigger("select")CheapSelect-all buttons
Heavy work on every selectExpensiveAvoid — keep handlers light

Migration from .select() to .on("select") does not change performance — it is a clearer, supported API.

Key Takeaways

  • Role: legacy shorthand for the text-highlight select event.
  • Modern API: .on("select", fn) and .trigger("select").
  • Not dropdowns: HTML <select> uses change.
  • Deprecated: bind form since jQuery 3.3 — migrate when you touch old files.

One line: treat .select() as legacy — use .on("select") / .trigger("select") for text highlights.

Frequently Asked Questions

The .select() method has two roles. With a handler — .select(handler) or .select(eventData, handler) — it binds a function that runs when the user highlights text inside an input or textarea. With no arguments — .select() — it triggers the select event, running bound handlers and typically selecting all text. Binding has been part of jQuery since 1.0 and is deprecated since 3.3. Do not confuse this with HTML <select> dropdowns.
Yes. The binding signatures .select(handler) and .select(eventData, handler) are deprecated since jQuery 3.3. Use .on("select", handler) instead. The no-argument .select() trigger still works, but .trigger("select") is clearer. Legacy code continues to run in jQuery 3.x.
.select(handler) registers a callback and does not fire immediately. .select() with no arguments triggers the select event — the same as .trigger("select") — and usually selects all text in the field. Check whether parentheses contain a function before reading legacy code.
Replace .select(fn) with .on("select", fn). Replace .select(data, fn) with .on("select", data, fn). Replace no-arg .select() with .trigger("select"). Cleanup with .off("select"). Under the hood, .select(handler) already delegates to .on("select").
No. jQuery .select() is shorthand for the select event — text highlighting inside inputs and textareas. HTML <select> dropdowns use the change event when the user picks an option.
No. Direct .select(fn) only binds to elements that already match. For dynamic fields, use .on("select", "input", fn) on a parent. That is one reason to prefer .on() over the shorthand.

Next: submit event

Learn how to bind handlers when the user submits a form.

submit 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