English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

HTML Reference Manual

HTML tag大全

HTML onselect event attribute

onselect is used to get or set the event handler function for the select event of the current window

HTML Event Attributes

Online Example

Execute JavaScript after selecting some text in the <input> element

<!DOCTYPE html>
<html>
<head>
<title>HTML onselect event attribute usage (Basic Tutorial Website oldtoolbag.com)</title>
<script>
function showMsg()
{
 alert("You have selected some text information!");
}
</script>
</head>
<body>
Some text: <input type="text" value="Select me!!" onselect="showMsg()">
<p>showMsg() function is triggered when text information in the input field is selected. The function pops up some information./p>
</body>
</html>
Test See ‹/›

Browser Compatibility

IEFirefoxOperaChromeSafari

All major browsers support the onselect event attribute

Definition and Usage

The onselect attribute is triggered when some text is selected in the element.

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

HTML 4.01 and HTML5differences between

No difference.

Syntax

<element onselect="script">

Attribute Value

ValueDescription
scriptSpecifies the script to be executed when the onselect event is triggered.
HTML Event Attributes