.select() methodThe .select() method in jQuery is used to bind an event handler to the select event on the <input type="text"> or <textarea> elements.
It is also used to trigger select event on an element.
.select() method Syntax.select() .select(handler) .select(eventData,handler)
| Parameter | Type | Description |
|---|---|---|
handler |
Function | A function to execute when the select is triggered on the matched element. |
eventData |
Anything | Additional data passed to the event handler. |
.select() method ExampleWhen user make a text selection inside a <inpt type="text"> or <textarea>, a select event will be triggered and sent to the box element.
Trigger select event on all inputs.
It will select the text inside the last element that get select event.
$("input").select();
HTML
<p><input type="text" name="username" value="Select some text inside me"></p>
$( "input" ).select(function() {
console.log("Something was selected inside inputbox "+$(this).attr("name"));
});
