removeEventListener
Overview
Section titled “Overview”The removeEventListener method allows you to remove previously registered event listeners from Htag events. This is useful for cleaning up event listeners when they are no longer needed.
Syntax
Section titled “Syntax”window.htag.api('1').removeEventListener(eventName, handler);Parameters
Section titled “Parameters”eventName(string): The name of the event to stop listening forhandler(function): The exact function reference that was used when adding the listener
Example
Section titled “Example”const readyListener = () => { console.log('Htag is ready');};
// Add the event listenerwindow.htag.api('1').addEventListener('ready', readyListener);
// Later, remove the event listener when no longer neededwindow.htag.api('1').removeEventListener('ready', readyListener);Important Notes
Section titled “Important Notes”- You must pass the same function reference to
removeEventListenerthat you passed toaddEventListener - Anonymous functions cannot be removed, so always use named functions or stored function references
- In case you want to get just one update (one shot listener), use addEventListener with
{ once: true }option (full example in addEventListener doc)
Related Methods
Section titled “Related Methods”- addEventListener: Add an event listener
- Events: Learn more about the supported events