Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

222
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!