79493704

Date: 2025-03-08 00:52:54
Score: 1
Natty:
Report link

To remove all event listener to an element just iterate through the property and nullify event related properties.

E.g: Nullify all property that startWith on which always denotes event handlers.

for (const property in element) {
  if (element[property] && property.startsWith('on')) {
    element[property] = null
    console.log('cleanup removed listener from ' + element.nodeName, property)
  }
}

This also related to what @john-henckel. Also this only applies to a single element, its children won't be affected.

Reasons:
  • Long answer (-0.5):
  • Has code block (-0.5):
  • User mentioned (1): @john-henckel
  • Low reputation (1):
Posted by: Elom Emmanuel