Javascript DOM HTML Paragraph handle paste Event

Introduction

Execute a JavaScript when pasting some text in a <p> element.

The contenteditable is set to "true".

View in separate window

<!DOCTYPE html>
<html>
<body>

<p contenteditable="true" 
   onpaste="myFunction()">Try to paste something inside this paragraph.</p>

<p id="demo"></p>
<script>
function myFunction() {//from   ww w  .ja  v  a2 s  .  c o m
  document.getElementById("demo").innerHTML = "You pasted text!";
}
</script>

</body>
</html>



PreviousNext

Related