Horje
What is HTML onselect Event Attribute
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 of HTML onselect Event Attribute

It will Execute a JavaScript after some text has been selected in an <input> element.
index.html
Example: HTML
 <input type="text" onselect="myFunction()" value="Hello world!"> 

Output should be:

Example of HTML onselect Event Attribute

Definition and Usage of HTML onselect Event Attribute

The onselect attribute fires after some text has been selected in an element.

Browser Support of HTML onselect Event Attribute

Browser Support of HTML onselect Event Attribute

Syntax of HTML onselect Event Attribute

<element onselect="script">

Attribute Values of HTML onselect Event Attribute

Value Description
script The script to be run on onselect

Technical Details of HTML onselect Event Attribute

Supported HTML tags: <input type="file">, <input type="password">, <input type="text">, and <textarea>

How to add a JavaScript after some text has been selected in an <input> element

The function myFunction() is triggered when some text is selected in the input field. The function shows a message.

index.html
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>

Output should be:

How to add a JavaScript after some text has been selected in an <input> element




html event attributes

Related Articles
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

Single Articles
Example of HTML onselect Event AttributeForm Events Attribute
Definition and Usage of HTML onselect Event AttributeForm Events Attribute
Browser Support of HTML onselect Event AttributeForm Events Attribute
Syntax of HTML onselect Event AttributeForm Events Attribute
Attribute Values of HTML onselect Event AttributeForm Events Attribute
Technical Details of HTML onselect Event AttributeForm Events Attribute
How to add a JavaScript after some text has been selected in an <input> elementForm 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