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

207
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar

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 Denunciar

0

i think this also work

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