When the user cuts the element’s text, the oncopy attribute triggers in HTML.
Example
You can try to run the following code to implement the oncopy attribute −
<!DOCTYPE html>
<html>
<body>
<input type = "text" oncopy="display()" value = "Copy me">
<h2 id = "test">Try to copy the above text.</h2>
<script>
function display() {
document.getElementById("test").innerHTML = "Your copied text worked!";
}
</script>
</body>
</html>