jQuery Select Event

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

What You’ll Learn

The select event fires when the user highlights text inside an <input> or <textarea> — not when they change the value, and not on dropdown <select> elements. This tutorial covers .on("select"), eventData, .trigger("select"), reading selected text, comparison with change and click, and the official jQuery API demos.

01

.on()

Bind handler

02

Highlight

Drag to select

03

.trigger()

Select all

04

input

+ textarea

05

vs change

Different

06

Since 1.7

Modern API

Introduction

Rich text editors, copy-to-clipboard buttons, and formatting toolbars often need to know when the user highlights a word or phrase. The select event is the browser signal for “the user just selected text inside this field.”

The official jQuery API distinguishes the select event (bound with .on("select") since 1.7) from the deprecated .select() method. To programmatically run select handlers — and select all text in the field — use .trigger("select") since jQuery 1.0.

⚠️
Not the <select> dropdown

The jQuery select event is about text selection (highlighting characters). Dropdown menus use the change event when the user picks a new option. The similar names confuse beginners — this page covers text highlight only.

Understanding the select Event

The select event is sent to an element when the user makes a text selection inside it. It applies to text <input> fields and <textarea> boxes — not checkboxes, radios, or <select> dropdowns.

Placing the cursor without highlighting text does not fire select. The user must select one or more characters — typically by click-dragging, double-clicking a word, or using Shift+arrow keys. Each new selection inside the same field can fire the event again.

💡
Beginner Tip

When you call .trigger("select"), jQuery runs your handler and performs the default action — usually selecting all text in the input. That matches the official API demo where clicking Trigger highlights the entire field.

📝 Syntax

The modern jQuery API for the select event has two main forms — binding a handler and triggering the event:

1. Bind a handler — .on("select" [, eventData ], handler) (since 1.7)

jQuery
.on( "select" [, eventData ], handler )
  • eventData — optional object passed to the handler as event.data.
  • handler — function called each time select fires: function( event ) { ... }.

2. Event delegation — .on("select", selector, handler)

jQuery
$( "#editor" ).on( "select", "textarea", function( event ) {
  // runs when user highlights text in any textarea inside #editor
} );

3. Trigger the event — .trigger("select") (since 1.0)

jQuery
.trigger( "select" )
  • Runs bound select handlers on the matched element(s).
  • Also fires the default action — typically selects all text in the field.

4. Unbind — .off("select" [, selector] [, handler])

jQuery
$( "#target" ).off( "select" );              // remove all select handlers
$( "#editor" ).off( "select", "textarea", fn ); // remove delegated handler

Official jQuery API examples

jQuery
$( "#target" ).on( "select", function() {
  alert( "Handler for `select` called." );
} );

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

Return value

  • .on() and .trigger() return the original jQuery object for chaining.
  • Handler return values are ignored unless you use return false.

⚡ Quick Reference

GoalCode
Bind select handler$("#target").on("select", fn)
Pass data to handler$("#target").on("select", { id: 1 }, fn)
All inputs and textareas$(":input").on("select", fn)
Delegated on textareas$("#editor").on("select", "textarea", fn)
Trigger select (select all)$("#target").trigger("select")
Get selected text (input)el.value.substring(el.selectionStart, el.selectionEnd)
Remove select handlers$("#target").off("select")

📋 select vs change vs click vs <select> dropdown

Four easily confused concepts — the select event is not the HTML element.

select event
highlight

User drags to highlight text in input or textarea — value may stay the same

change event
value diff

Committed value changed — use for dropdowns, checkboxes, and edited text on blur

click event
press

Mouse down+up on element — fires even when user only places cursor, no highlight

<select> element
dropdown

HTML dropdown menu — use .on("change") when user picks a new option

Examples Gallery

Examples 1–2 follow the official jQuery API documentation. Examples 3–5 extend the official :input demo, selected-text length display, and eventData. Use the Try-it links to run each snippet in the browser.

📚 Binding & Triggering

Official jQuery demos for select handlers and programmatic triggers.

Example 1 — Official Demo: Bind Handler on #target

Alert when the user highlights any portion of text in the input field.

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

How It Works

.on("select", fn) registers on the text input. The handler runs when the browser fires select after the user highlights characters — not on every click or keystroke.

Example 2 — Official Demo: #other Triggers Select on #target

One button programmatically fires the select handler and selects all text in the field.

jQuery
$( "#target" ).on( "select", function() {
  alert( "Handler for `select` called." );
} );

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

How It Works

.trigger("select") synthetically fires the event and performs the default select-all behavior. Useful for “Select all” buttons that should run the same handler as manual highlighting.

📈 Practical Selection Patterns

Official extended demo, selection length, and formatting toolbar patterns.

Example 3 — Official Demo: :input Selection Notice

Bind on all inputs — show a fading message whenever text is selected in any field.

jQuery
$( ":input" ).on( "select", function() {
  $( "#notice" ).text( "Something was selected" ).show().fadeOut( 1000 );
} );
Try It Yourself

How It Works

$(":input") matches text inputs, textareas, buttons, and other form controls — but select only fires meaningfully on text fields and textareas. Checkboxes and buttons ignore text selection.

Example 4 — Show Selected Character Count

Read selectionStart and selectionEnd to display how many characters the user highlighted.

jQuery
$( "#bio" ).on( "select", function() {
  var el = this;
  var len = el.selectionEnd - el.selectionStart;
  var text = $( el ).val().substring( el.selectionStart, el.selectionEnd );
  $( "#stats" ).text( len + " chars selected: "" + text + """ );
} );
Try It Yourself

How It Works

Native input elements expose selectionStart and selectionEnd — slice .val() between them for the highlighted substring. For complex pages, consider a plugin or document.getSelection().

Example 5 — Pass eventData to Show a Format Toolbar

Pass toolbar config via event.data — show bold/italic hints when text is selected.

jQuery
$( "#editor" ).on( "select", { toolbar: "basic" }, "textarea", function( event ) {
  var len = this.selectionEnd - this.selectionStart;
  if ( len > 0 ) {
    $( "#toolbar" ).text( "Toolbar: " + event.data.toolbar + " | " + len + " chars highlighted" ).show();
  } else {
    $( "#toolbar" ).hide();
  }
} );
Try It Yourself

How It Works

Combines delegation, eventData, and selection length. Real rich-text editors use similar patterns — show formatting controls only when the user has highlighted text.

🚀 Common Use Cases

  • Copy / share selection — enable a “Copy quote” button when the user highlights text in a textarea.
  • Formatting toolbar — show bold, italic, or link controls when characters are selected.
  • Character limits — warn if the user selects more characters than a paste limit allows.
  • Analytics — log which phrases users highlight in feedback forms.
  • Select-all button$("#field").trigger("select") runs handlers and selects all text.
  • Contextual help — show a definition popup for the highlighted word.

🧠 How the select Event Flows

1

User highlights text

Click-drag, double-click a word, or Shift+arrow keys inside an input or textarea.

drag
2

Browser fires select

Native select event sent to the field — cursor-only clicks do not qualify.

select
3

jQuery runs handler

Your .on("select", fn) callback executes — read selection via selectionStart/selectionEnd.

handler
4

UI updates

Show toolbar, copy button, or selection stats. On .trigger("select"), default action also selects all text.

📝 Notes

  • Bind with .on("select", handler) since jQuery 1.7 — not the deprecated .select(handler) method.
  • Trigger with .trigger("select") since jQuery 1.0 — also performs default select-all action.
  • Limited to text <input> and <textarea> — not <select> dropdowns.
  • Cursor placement alone does not fire select — user must highlight characters.
  • Getting selected text differs by browser — use selectionStart/selectionEnd on inputs or plugins for complex cases.
  • Not the same as the HTML <select> element — that uses change when options change.
  • Use .off("select") to remove handlers — avoid deprecated .unbind("select").

Browser Support

The select event is supported on text inputs and textareas in browsers jQuery targets. jQuery’s .on("select") (since 1.7) and .trigger("select") (since 1.0) work across jQuery 1.x, 2.x, and 3.x.

jQuery 1.7+

jQuery select event

Supported in jQuery 1.x, 2.x, and 3.x across modern browsers. Native equivalent: element.addEventListener('select', fn) on inputs and textareas. Cross-browser selected-text retrieval may need helpers beyond the event itself.

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 Universal

Bottom line: Safe in any jQuery project. Prefer .on('select') over deprecated .select() for binding. Remember: select event ≠ HTML

Conclusion

The jQuery select event reacts when users highlight text inside inputs and textareas. Bind handlers with .on("select", fn), pass optional eventData, and fire handlers programmatically with .trigger("select") — which also selects all text by default.

Do not confuse this event with dropdown <select> elements or the change event. Use selectionStart and selectionEnd to read highlighted text, and consider plugins for advanced cross-browser selection APIs.

💡 Best Practices

✅ Do

  • Bind with .on("select", handler) on inputs and textareas
  • Use selectionStart and selectionEnd to read highlighted text on inputs
  • Delegate on container elements for multiple textareas in an editor
  • Explain to teammates that select event ≠ HTML <select> dropdown
  • Use .trigger("select") for Select-all buttons that should run the same handler

❌ Don’t

  • Bind .on("select") on <select> dropdowns — use change
  • Expect select when the user only clicks to place the cursor
  • Assume the jQuery event object includes selected text on all browsers
  • Use deprecated .select(handler) in new code
  • Confuse text selection with value change — use change or input for edits

Key Takeaways

Knowledge Unlocked

Six things to remember about the select event

Highlight, not dropdown.

6
Core concepts
02

Highlight

Drag select

Trigger
03

.trigger()

Select all

Programmatic
04

<select>

Not this

Confusion
len05

selectionStart

Read text

Native
.off06

.off("select")

Unbind

Cleanup

❓ Frequently Asked Questions

The select event fires when the user makes a text selection inside an element — by clicking and dragging the mouse to highlight characters. It is limited to text input fields and textareas. Bind handlers with .on('select', handler) since jQuery 1.7. Do not confuse it with the HTML <select> dropdown element or the change event on dropdowns.
No. Merely placing the cursor (the insertion point) inside a field does not trigger select. The user must highlight at least one character — click-drag or double-click a word. Keyboard Shift+arrow selection also fires select in supporting browsers.
Calling .trigger('select') runs bound select handlers and also fires the browser's default select action — typically selecting all text in the field. That is why the official jQuery demo selects the entire input when you click the Trigger button.
They measure different things. change fires when the field's value changes — picking a dropdown option or editing text and tabbing away. select fires when the user highlights a portion of existing text inside an input or textarea. You can select text without changing the value.
There is no single cross-browser property on the jQuery event object. Common approaches: document.getSelection().toString(), window.getSelection(), or for inputs specifically: element.selectionStart and element.selectionEnd to slice .val(). Many jQuery plugins wrap these differences.
The jQuery select event documentation limits the event to input fields and textareas. For contenteditable regions, use document.getSelection() with mouseup or selectionchange events instead.
Did you know?

When jQuery’s .trigger("select") runs, it invokes your handler and performs the browser default action — which for text inputs usually means selecting all text in the field. That is why the official API demo’s Trigger button both alerts and highlights the entire input. For handler-only execution without the default action, use .triggerHandler("select") instead.

Next: .select() Method

Legacy shorthand for binding and triggering text selection — deprecated since 3.3.

.select() method 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.

6 people found this page helpful