Javascript DOM onselect Event via addEventListener() method

Introduction

In JavaScript, using the addEventListener() method:

object.addEventListener("select",
       myScript);

This example uses the addEventListener() method to attach a "select" event to an input element.

View in separate window

<!DOCTYPE html>
<html>
<body>
Select some text: <input type="text" value="Hello world!" id="myText">
<p id="demo"></p>
<script>
document.getElementById("myText").addEventListener("select", myFunction);

function myFunction() {/*from   ww  w . j a  v a  2 s.  co m*/
  document.getElementById("demo").innerHTML = "You selected some text!";
}
</script>

</body>
</html>
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