HTML onselect event property

Example

Execute a JavaScript block when the text inside the <input> element is selected:

<input type="text" onselect="showMsg()" value="Hello world!">

Try it yourself

Browser support

IE Firefox Chrome Safari Opera

All major browsers support the 'onselect' attribute.

Definition and usage

The 'onselect' attribute triggers when the text in the element is selected.

The 'onselect' attribute can be used within the following elements: <input type="file">, <input type="password">, <input type="text">, <keygen>, and <textarea>.

Differences between HTML 4.01 and HTML5

None.

Syntax

<element onselect="script">

Attribute value

Value Description
script Script that runs when 'onselect' occurs.