onselectEvent

事件对象参考手册Event Object

Examples

Execute a piece of JavaScript code when text is selected:

<input type="text" onselect="myFunction">

Try it yourself »

Definition and Usage

The onselect event occurs when text within a text field is selected.

Syntax

In HTML:

<element onselect="SomeJavaScriptCode">

In JavaScript:

object.onselect=function(){SomeJavaScriptCode}

Parameters Description
SomeJavaScriptCode Required. Specifies the JavaScript to execute when the event occurs.


Browser Support

Internet ExplorerFirefoxOperaGoogle ChromeSafari

All major browsers support the onselect event


onselect in HTML

The onselect attribute can be used on: <input type="file">, <input type="password">, <input type="text">, <keygen>, and <textarea>.


事件对象参考手册Event Object Other extensions