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

234
Vistas
What is exact JavaScript analog of the on() jquery API?

At the moment the only thing, which makes me load ~100kb jQuery library are these 3 lines of code:

$(document).on('click', ".js-ya-share2-button", function() {
    this.parentElement.querySelector('.ya-share2__item_more').click();
});

How to reproduce the full functionality of without jQuery?

The code above allows to "attach" a function to elements, which hasn't been loaded yet. For example, to elements, which are loaded only when user scrolls the page down. How to make it with pure JavaScript?

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

0

This imo would be the exact analogy in vanilla JS:

document.addEventListener('click', function(event) {
    const desiredTargetElement = event.target.closest('.js-ya-share2-button'); 
    if (desiredTargetElement)
        desiredTargetElement.parentElement.querySelector('.ya-share2__item_more').click();
});

The reason we need to work with closest here rather than checking if the event target has the desired class is that you can have scenarios where the clicked element is actually a descendant of the element you're looking out for.

closest(selector), if called on the element that already matches the desired selector, will return the element itself.

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