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

130
Views
JQuery: función que se aplica solo al primer elemento con clase

Estoy tratando de actualizar los atributos modal y de video al hacer clic en el botón.

Funciona bien, pero el problema es que solo aplica esto cuando hago clic en el primer botón (primer elemento con la clase videoBtn), quiero que se aplique en todos los demás botones con la misma clase

aquí está mi código

 $(".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 answers
Answer question

0

No está usando el valor del elemento actualmente seleccionado, pero primero con la clase, debe usar $this en lugar de $('.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 Report

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 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!