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, it is actually not possible to cut content, 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:The following are three ways to cut elements/element content:

  • CTRL + X
  • Select cut from the browser's edit menu
  • Select the cut command from the right-click menu

Instance

Example 1

Execute JavaScript when cutting text in the <input> element:

<input type="text" oncut="myFunction()" value="Try to cut this text">

Try it yourself

Example 2

Execute JavaScript when cutting the text of the <p> element (note that contenteditable is set to "true"):

<p contenteditable="true" oncut="myFunction()">Try to cut this text</p>

Try it yourself

Syntax

In HTML:

<element oncut="myScript">

Try it yourself

In JavaScript:

object.oncut = function(){myScript};

Try it yourself

In JavaScript, use the addEventListener() method:

object.addEventListener("cut", myScript);

Try it yourself

Note:Internet Explorer 8 or earlier versions do not support addEventListener() method.

Technical details

Bubbling: Unterstützung
Cancellable: Unterstützung
Event type: ClipboardEvent
Unterstützte HTML-Tags: Alle HTML-Elemente

Browser-Unterstützung

Ereignisse Chrome IE Firefox Safari Opera
oncut Unterstützung Unterstützung Unterstützung Unterstützung Unterstützung

Verwandte Seiten

HTML DOM Referenzhandbuch:oncopy-Ereignis

HTML DOM Referenzhandbuch:onpaste-Ereignis