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 contenteditable set 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 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 an <input> element:

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

Try it yourself

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>

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: Support
Cancellable: Support
Event type: ClipboardEvent
Understøttede HTML tags: Alle HTML elementer

Browser understøttelse

Begivenheder Chrome IE Firefox Safari Opera
oncut Support Support Support Support Support

Relaterede sider

HTML DOM referencehåndbog:oncopy begivenhed

HTML DOM referencehåndbog:onpaste begivenhed