Javascript DOM onselect Event

Introduction

Execute a JavaScript when some text has been selected:

View in separate window

<!DOCTYPE html>
<html>
<body>

Select some of the text: <input type="text" value="Hello world!" onselect="myFunction()">

<script>
function myFunction() {//from   w w  w . j ava2 s.c om
  alert("You selected some text!");
}
</script>

</body>
</html>

The onselect event occurs after some text has been selected in an element.

The onselect event is mostly used on <input type="text"> or <textarea> elements.

Bubbles:
Cancelable:
Event type:
Supported HTML tags:



No
No
UiEvent if generated from a user interface, Event otherwise
<input type="file">,
<input type="password">,
<input type="text">, and
<textarea>



PreviousNext

Related