Javascript DOM onselect Event via HTML Tag onselect function

Introduction

In JavaScript:

object.onselect = function(){
       myScript};

This example uses the HTML DOM to assign an "onselect" 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").onselect = function() {myFunction()};

function myFunction() {/*from  w  w w.  j a v  a2s. 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