👀 Live Preview
Select text in the editable box and cut it (Ctrl+X or context menu Cut):
Cut some text to see the event fire.

The oncut attribute is an inline event handler that runs JavaScript when the cut event fires. That happens when the user cuts content — with Ctrl+X (Cmd+X on Mac), Edit → Cut, or the context menu Cut action. Unlike copy, cut removes the selection from the source after placing it on the clipboard. It is common on contenteditable regions, textarea, and input fields. Use it for validation before removal, logging edits, or customizing clipboard data with event.clipboardData. The cut event bubbles. For production sites, prefer addEventListener("cut", …) over inline handlers.
Inline JS.
Ctrl+X / Cut.
Editable div.
Cut vs copy.
Preferred way.
Cancel cut.
oncut AttributeThe primary purpose of oncut is to react when the user cuts text or content from an editable element. Common uses include validating that removed content is allowed, showing a “Text cut” message, logging editor changes, or customizing what lands on the clipboard via event.clipboardData. Because cut both copies and removes, your handler runs before the selection disappears — use event.preventDefault() to block the cut if needed.
Do not confuse oncut with oncopy. Copy duplicates content; cut moves it off the page. Pair with onpaste for full clipboard coverage. Avoid blocking cut without a good reason — users rely on Cut for editing and accessibility workflows.
In the cut handler, call event.preventDefault() to stop the selection from being removed and prevent the default clipboard update.
Set oncut on an editable element or assign element.oncut:
<script>
function handleCut() {
document.getElementById("status").textContent = "Content cut!";
}
</script>
<div contenteditable="true" oncut="handleCut()">
Select and cut this editable text.
</div>
<p id="status"></p>event when you need clipboardData or preventDefault().contenteditable, textarea, input, etc.element.oncut = function(e) { … }.element.addEventListener("cut", handler).cut event bubbles — you can delegate on a parent container.The oncut attribute accepts a string of JavaScript code:
oncut="handleCut()" — Call a named function.oncut="handleCut(event)" — Pass the event for clipboard access or cancellation.field.oncut = (e) => { … } assigns the handler.const editor = document.getElementById("editor");
editor.addEventListener("cut", (event) => {
const selection = window.getSelection().toString();
if (selection.length > 500) {
event.preventDefault();
document.getElementById("msg").textContent = "Cannot cut more than 500 characters.";
return;
}
document.getElementById("msg").textContent = "Cut allowed.";
});| Event | When it fires | Handler |
|---|---|---|
copy | User copies selection | oncopy |
cut | User cuts selection | oncut |
paste | User pastes | onpaste |
clipboardData | In copy/cut handler | setData / getData |
| Keyboard | Ctrl+X / Cmd+X | Fires cut |
| Bubbles? | cut yes | Delegate on parent |
| Target | Supported? | Notes |
|---|---|---|
contenteditable | Yes | Most common for rich inline editing |
<textarea>, <input> | Yes | Cut from form fields |
<div>, <p> | Sometimes | When text is selectable or contenteditable |
<pre>, <code> | Yes | Common for code snippets |
<img> | Limited | Copy image via browser, not text selection |
<button> | Sometimes | When button label text is selected |
oncut vs oncopy vs onpaste| Handler | When it fires | Typical use |
|---|---|---|
oncut | Content cut (copy + remove) | Validate before removing text |
oncopy | Content copied to clipboard | Feedback, attribution, logging |
onpaste | Content pasted from clipboard | Sanitize pasted input |
Inline oncut on contenteditable, addEventListener with validation, and comparing cut with copy events.
Select text in the editable box and cut it (Ctrl+X or context menu Cut):
Cut some text to see the event fire.
Show feedback when the user cuts content from an editable div:
<div contenteditable="true" oncut="handleCut()">
Try cutting this text!
</div>
<script>
function handleCut() {
document.getElementById("msg").textContent = "Text cut!";
}
</script>The browser fires cut when the clipboard receives content and the selection is removed. Your inline handler runs at that moment.
Assign the handler with element.oncut or addEventListener:
const editable = document.getElementById("dynamicEditable");
editable.oncut = function () {
console.log("Dynamic content cut!");
};
// Or preferred form:
editable.addEventListener("cut", () => {
console.log("Cut detected via addEventListener.");
});Register the listener once at page load. When the user cuts, your handler runs before the default removal completes.
Listen for both clipboard events on the same field:
field.addEventListener("cut", () => {
log("cut — removed from field");
});
field.addEventListener("copy", () => {
log("copy — duplicated to clipboard");
});Both are clipboard events. oncut handles move-style removal; oncopy handles duplication only.
preventDefault() unless validation truly requires it.Highlights editable content.
Ctrl+X or Cut command.
Handler runs on element.
Clipboard + source updated.
The cut event and oncut handler are supported in all modern browsers — Chrome, Firefox, Safari, and Edge. clipboardData and preventDefault() work in current browsers during the cut event.
oncut supportAll major browsers fire the underlying event and honor the oncut handler attribute.
Bottom line: Universal support for the cut event. Test with keyboard cut (Ctrl+X) and context menu Cut on contenteditable and textarea elements.
oncut.preventDefault() only when cut must be cancelled (e.g. protected content).The oncut attribute runs JavaScript when the user cuts content from an editable element and the cut event fires. Use it for validation, feedback, or customizing clipboard data with event.clipboardData.
Prefer addEventListener("cut", …), respect user expectations, and pair with oncopy and onpaste when building clipboard-aware editors.
oncutBookmark these before wiring your next event handler.
cut fires.
Eventcontenteditable.
ScopeCancel cut.
PatternPreferred.
ModernCut vs copy.
Notecut event fires — when the user cuts content from an editable element.contenteditable divs, textarea, input, and other elements where cut is allowed.event.preventDefault() in the cut handler to cancel the operation and keep content in place.oncut copies and removes content. oncopy duplicates content and leaves it in place.element.addEventListener("cut", …). Inline oncut works for simple demos.Practice inline oncut, addEventListener, and cut vs copy in the Try It editor.
5 people found this page helpful