HTMLElement.onNodeInserted method
HTMLElement › onNodeInserted
Official
Adds an event listener to the element when it is inserted into the DOM.Signature:
onNodeInserted(this: HTMLElement, listener: () => unknown, once?: boolean | undefined): () => voidParameters:
| Parameter | Type | Description |
|---|---|---|
| this | HTMLElement | |
| listener | () => unknown | the callback to call when this node is inserted into the DOM. |
| once? | boolean | undefined | if true, this will only fire once and then unhook itself. |
Returns: () => void — destroy - a function to remove the event handler to avoid memory leaks.
Example:
document.body.onNodeInserted(() => { console.log('node inserted');});