![]() |
The
onselect event attribute in HTML triggers a script when a user selects some text within an element. It is part of the Event Attributes and is primarily used with text-based input elements like <input type="text"> and <textarea> .
|
Example:
HTML
<input type="text" onselect="myFunction()" value="Hello world!">
The onselect attribute fires after some text has been selected in an element.
<element onselect="script">
Value | Description |
---|---|
script | The script to be run on onselect |
Supported HTML tags: | <input type="file">, <input type="password">, <input type="text">, and <textarea> |
---|
The function myFunction() is triggered when some text is selected in the input field. The function shows a message.
Example:
HTML
<!DOCTYPE html>
<html>
<body>
Some text: <input type="text" value="Select me!!" onselect="myFunction()">
<p>The function myFunction() is triggered when some text is selected in the input field. The function shows a message.</p>
<script>
function myFunction() {
alert("You have selected some text!");
}
</script>
</body>
</html>
html event attributes |
List of Form Events Attribute | Form Events Attribute |
What is HTML onblur Event Attribute | Form Events Attribute |
What is HTML onchange Event Attribute | Form Events Attribute |
What is HTML oncontextmenu Event Attribute | Form Events Attribute |
What is HTML onfocus Event Attribute | Form Events Attribute |
What is HTML oninput Event Attribute | Form Events Attribute |
What is HTML oninvalid Event Attribute | Form Events Attribute |
What is HTML onreset Event Attribute | Form Events Attribute |
What is HTML onsearch Event Attribute | Form Events Attribute |
What is HTML onselect Event Attribute | Form Events Attribute |
What is HTML onsubmit Event Attribute | Form Events Attribute |
Example of HTML onselect Event Attribute | Form Events Attribute |
Definition and Usage of HTML onselect Event Attribute | Form Events Attribute |
Browser Support of HTML onselect Event Attribute | Form Events Attribute |
Syntax of HTML onselect Event Attribute | Form Events Attribute |
Attribute Values of HTML onselect Event Attribute | Form Events Attribute |
Technical Details of HTML onselect Event Attribute | Form Events Attribute |
How to add a JavaScript after some text has been selected in an <input> element | Form Events Attribute |
Read Full: | Form Events Attribute |
Type: | Develop |
Category: | Web Tutorial |
Sub Category: | Form Events Attribute |
Uploaded by: | Admin |
Views: | 18 |
Reffered: https://www.w3schools.com/tags/ev_onselect.asp