Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

193
Vistas
How to list event listeners of the html element in runtime without the dev tools?

There is this answer: can I programmatically examine and modify Javascript event handlers on html elements? but it doesn't provide the runtime solution

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

There isn't any direct API for this, but it can be accessed in a kind of intrusive way.

By overriding HTMLElement.prototype.addEventListener we can catch added events and store them in an array for example.

const listeners = []
const originalAddEventListener = HTMLElement.prototype.addEventListener
HTMLElement.prototype.addEventListener = function(type, listener, options) {
    listeners.push({
    element: this,
    type,
    listener,
    options
  })
  // call the original listener with current this and provided arguments
  return originalAddEventListener.call(this, type, listener, options)
}

Full snippet with example:

const listeners = []
const originalAddEventListener = HTMLElement.prototype.addEventListener
HTMLElement.prototype.addEventListener = function(type, listener, options) {
  listeners.push({
    element: this,
    type,
    listener,
    options
  })
  return originalAddEventListener.call(this, type, listener, options)
}

document.querySelector('p').addEventListener('click', () => {
  console.log('clicked')
}, false)

document.querySelector('button').addEventListener('click', () => console.log(listeners))
p {
  width: 100px;
  height: 100px;
  background: red;
  color: white;
}
<button>list listeners</button>
<p>click me</p>

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda