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

164
Vistas
jQuery feature with pure JS

There is feature click binding on selector

$(document).on("click", ".onClass", function () {
    //your code
    var element = $(this); // to get clicked element
});

Is there any analog with pure js?

P.S. I have seen this solution How to get the element clicked (for the whole document)? but it is not a solution i am expecting.

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

0

You can bind the event listener to the document in the same way, but you need to test the target element to see if either it or one of its ancestors, matches the selector.

document.addEventListener('click', (event) => {
    const selector = ".onClass";
    const element = event.target;
    if (!element.closest(selector)) return; // No match so abort here
    // Otherwise: Do stuff with element
});
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