THE WORLD'S LARGEST WEB DEVELOPER SITE
HTMLCSSJAVASCRIPTSQLPHPBOOTSTRAPJQUERYANGULARXML
 

onselect Event

Event Object Reference Event Object

Example

Execute a JavaScript when some text has been selected:

<input type="text" onselect="myFunction()">
Try it Yourself »

More "Try it Yourself" examples below.


Definition and Usage

The onselect event occurs after some text has been selected in an element.

The onselect event is mostly used on <input type="text"> or <textarea> elements.


Browser Support

Event
onselect Yes Yes Yes Yes Yes

Syntax

In HTML:

<element onselect="myScript">
Try it Yourself »

In JavaScript:

object.onselect=function(){myScript};
Try it Yourself »

In JavaScript, using the addEventListener() method:

object.addEventListener("select", myScript);
Try it Yourself »

Note: The addEventListener() method is not supported in Internet Explorer 8 and earlier versions.


Technical Details

Bubbles: No
Cancelable: No
Event type: UIEvent if generated from a user interface, Event otherwise
Supported HTML tags: <input type="file">, <input type="password">, <input type="text">, <keygen>, and <textarea>
DOM Version: Level 2 Events

Examples

More Examples

Example

Using the select() method of the HTML DOM Input Text Object to select some content of a text field. When this happens, the onselect event fires, which will trigger an alert function.

// Select the contents of a text field
function mySelectFunction() {
    document.getElementById("myText").select();
}

// Alert some text when the text in the text field has been selected
function myAlertFunction() {
    alert("You selected some text!");
}
Try it Yourself »

Event Object Reference Event Object