Web APIs
Event.preventDefault()
Sets the canceled flag if the event is cancelable and the listener is not passive. dispatchEvent then returns false.
Formal Syntax & Structure
javascript syntaxjavascript
event.preventDefault()Return Value
undefined
No return value.
Working Example
Example Snippetjavascript
const b=document.createElement("button");b.addEventListener("demo",e=>e.preventDefault());console.log(b.dispatchEvent(new Event("demo",{cancelable:true})),b.dispatchEvent(new Event("demo")));