oncut Event
Definition and Usage
The oncut event occurs when the user cuts the content of an element.
Although all HTML elements support the oncut event, in fact, content cannot be cut, such as <p> elements, unless the element has set contenteditable to "true" (see more examples below).
Tip:The oncut event is mainly used for <input> elements with type="text".
Tip:Here are three ways to cut elements/element content:
- CTRL + X
- Select the cut command from the browser's edit menu
- Select the cut command from the right-click menu
Instance
Example 1
Execute JavaScript when cutting text in an <input> element:
<input type="text" oncut="myFunction()" value="Try to cut this text">
Example 2
Execute JavaScript when cutting text in a <p> element (note that contenteditable is set to "true"):
<p contenteditable="true" oncut="myFunction()">Try to cut this text</p>
Syntax
In HTML:
<element oncut="myScript">
In JavaScript:
object.oncut = function(){myScript};
In JavaScript, use the addEventListener() method:
object.addEventListener("cut", myScript);
Note:Internet Explorer 8 or earlier versions do not support addEventListener() Method.
Technical Details
Bubble: | Support |
---|---|
Cancellable: | Support |
Event Type: | ClipboardEvent |
Supported HTML Tags: | All HTML Elements |
Browser Support
Events | Chrome | IE | Firefox | Safari | Opera |
---|---|---|---|---|---|
oncut | Support | Support | Support | Support | Support |