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

213
Views
jQuery find ID of clicked button by class

I have numerous buttons on my page with the same class names. However these buttons have different ID's. How do i do this:

$(".vote").click(function(){
     var id = $(this).{ID OF CLICKED BUTTON};
});

How can i make this pseudo code work?

Thanks

over 4 years ago · Santiago Trujillo
3 answers
Answer question

0

$(".vote").click(function(){
     var id = this.id;
});

The ID is accessible directly from the element. There's absolutely no need to use a jQuery method.

over 4 years ago · Santiago Trujillo Report

0

With jQuery object (not necessary)

$(".vote").click(function(){
  var id = $(this).attr('id');
});


Without jQuery object (faster)

$(".vote").click(function(){
  var id = this.id;
});
over 4 years ago · Santiago Trujillo Report

0

i think this also work

 $("body").on("click",".vote",function(){
    var id = this.id;
 });
over 4 years ago · Santiago Trujillo 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!