Web APIs
Listener once option
Automatically unregisters the listener before its first invocation.
Formal Syntax & Structure
javascript syntaxjavascript
target.addEventListener(type, callback, { once: true })Parameters & Attributes
| Name | Type | Description |
|---|---|---|
| type | string | Event type. |
| callback | function | EventListener object | Listener. |
Working Example
Example Snippetjavascript
const b=document.createElement("button");let n=0;b.addEventListener("click",()=>n++,{once:true});b.click();b.click();console.log(n);