Javascript DOM onpaste Event via addEventListener() method

Introduction

In JavaScript, using the addEventListener() method:

object.addEventListener("paste",
       myScript);

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

View in separate window

<!DOCTYPE html>
<html>
<body>
<input type="text" id="myInput" value="Try to paste something in here" size="40">

<p id="demo"></p>
<script>
document.getElementById("myInput").addEventListener("paste", myFunction);

function myFunction() {/*w  w  w .  jav  a 2s. co  m*/
  document.getElementById("demo").innerHTML = "You pasted text!";
}
</script>

</body>
</html>
Bubbles: Yes
Cancelable: Yes
Event type: ClipboardEvent
Supported HTML tags: All HTML elements



PreviousNext

Related