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

125
Vistas
JQuery - Function applying only for first element with class

I'm trying to update a modal & video attributes on button click.

It works well but the problem is that it only apply this when i click on the first button ( first element with the class videoBtn ), i want it to be applied on all other buttons with the same class

here is my code

$(".videoBtn").click(function(){
        $("#video").attr('src',$(".videoBtn").data('src'));
        $(".modal").attr('id', $(".videoBtn").data('target').substring(1));
      });
about 4 years ago · Juan Pablo Isaza
2 Respuestas
Responde la pregunta

0

You are not using value of currently clicked element, but first with class, you should use $this instead of $('.videoBtn')

$(".videoBtn").click(function(){
   $("#video").attr('src',$(this).data('src'));
   $(".modal").attr('id', $(this).data('target').substring(1));
});
about 4 years ago · Juan Pablo Isaza Denunciar

0

$(".videoBtn").each(function(){
  $(this).on('click', function() {
    $("#video").attr('src',$(".videoBtn").data('src'));
    $(".modal").attr('id', $(".videoBtn").data('target').substring(1));
  })
})
about 4 years ago · Juan Pablo Isaza 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