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

189
Views
¿Cómo puedo aplicar javascript a varios Elementos con diferentes ID a la vez?

Tengo este código que me permite detener la reproducción de videos de YouTube una vez que se presiona un botón. Aquí hay un ejemplo:

 //Hotel Post <script> $(document).ready(function() { // set unique id to videoplayer for the Webflow video element var src = $('#videoplayer').children('iframe').attr('src'); // when object with class open-popup is clicked... $('.open-popup.left').click(function(e) { e.preventDefault(); // change the src value of the video $('#videoplayer').children('iframe').attr('src', src); $('.popup-bg').fadeIn(); }); // when object with class close-popup is clicked... $('.close-modal-button').click(function(e) { e.preventDefault(); $('#videoplayer').children('iframe').attr('src', ''); $('.popup-bg').fadeOut(); }); }); </script> //Gans to go <script> $(document).ready(function() { // set unique id to videoplayer for the Webflow video element var src = $('#videoplayer2').children('iframe').attr('src'); // when object with class open-popup is clicked... $('.open-popup.left').click(function(e) { e.preventDefault(); // change the src value of the video $('#videoplayer2').children('iframe').attr('src', src); $('.popup-bg').fadeIn(); }); // when object with class close-popup is clicked... $('.close-modal-button').click(function(e) { e.preventDefault(); $('#videoplayer2').children('iframe').attr('src', ''); $('.popup-bg').fadeOut(); }); }); </script>

Tengo alrededor de 14 videos como este incrustados en mi sitio y hace que las cosas sean más lentas, porque tengo uno de estos scripts para cada video. ¿Hay alguna manera de que pueda seleccionar varias identificaciones a la vez o algo así? Entonces, ¿tengo un guión para todos los videos?

Apreciaría la ayuda. Muchas gracias. Pablo

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Una forma es configurar todos los videos para que tengan un nombre de clase común, como video y almacenar la variable src en un atributo de datos.

 $(document).ready(function() { // set unique id to videoplayer for the Webflow video element $('.video').each(function() { let src = $(this).children('iframe').attr('src'); $(this).attr('data-src', src); }) // when object with class open-popup is clicked... $('.open-popup.left').click(function(e) { e.preventDefault(); // change the src value of the video $('.video').each(function() { $(this).children('iframe').attr('src', $(this).data('src')); $('.popup-bg').fadeIn(); }); // when object with class close-popup is clicked... $('.close-modal-button').click(function(e) { e.preventDefault(); $('.video').each(function() { $(this).children('iframe').attr('src', ''); $('.popup-bg').fadeOut(); }); });

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!