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

205
Views
jQuery encuentra la ID del botón en el que se hizo clic por clase

Tengo numerosos botones en mi página con los mismos nombres de clase. Sin embargo, estos botones tienen ID diferentes. Cómo hago esto:

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

¿Cómo puedo hacer que este pseudocódigo funcione?

Gracias

over 4 years ago · Santiago Trujillo
3 answers
Answer question

0

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

El ID es accesible directamente desde el elemento. No hay absolutamente ninguna necesidad de usar un método jQuery.

over 4 years ago · Santiago Trujillo Report

0

Con objeto jQuery (no es necesario)

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


Sin objeto jQuery (más rápido)

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

0

creo que esto también funciona

 $("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!