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

206
Views
How I can rewrite this Jquery code into Vanilla JS

As I mentioned in the title, How can i rewrite this Jquery Code into Vanilla JS

Here's Jquery Code Example:

$(document).on('click', '.btn', function())

about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

This is how VanillaJS snippet could look like

document.addEventListener('click', function (event) {
    if (!event.target.matches('.btn')) return;
    event.preventDefault();
    // Your code
}, false);

or if You prefer to attach click handler to specific element

var clickMe = document.querySelector('.click-me');
clickMe.addEventListener('click', function (event) {    // Dosomething... });
about 4 years ago · Juan Pablo Isaza Report

0

You can use the querySelector function which is similar to the $ in jQuery and add the desired listener using the addEventListener. If you want a list of all elements of the btn class you can use the querySelectorAll function.

See documentation here:

  • querySelector
  • querySelectorAll
  • addEventListener
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!