oncut
The oncut event attribute in HTML activates a function when content is cut from an element, typically in editable areas.
oncut event
The oncut
event attribute is triggered when a user cuts content from an element, such as text in an input field. You can define a script to execute when this event occurs.
Syntax
In HTML
index.html
<element oncut="myScript">
In JS
script.js
object.oncut = function(){myScript};
addEventListener()
function is used. In JavaScript, the
script.js
object.addEventListener("cut", myScript);
Example
::event-oncut
::
index.html
<!DOCTYPE html>
<html>
<body>
<h1>HTML DOM Events</h1>
<h2>The oncut Event</h2>
<input type="text" oncut="myFunction()" value="Try to cut this text">
<p id="demo"></p>
<script>
function myFunction() {
document.getElementById("demo").innerHTML = "You cutted text!";
}
</script>
</body>
</html>
Values
<script>
- Specifies the function to run when the event is triggered.
Conclusion
The oncut
event allows you to execute a function when content is cut from an element, usually in editable areas. It is frequently used with <input>
elements of type="text"
. By specifying a script, you can customize the behavior when content is removed.