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

89
Vistas
Audio only working for one function at a time when user clicks a href tag

I have several video tags wrapped inside of a a-href tag. When the user clicks on the a href, I would like that to trigger an audio clip before being redirected to another landing page. Currently it only works for one function at a time (audio being played) and I would like it to work for all of them.

Here is my code:

HTML:

    <a href="https://www.google.com/" id="h-link" class="h-swoosh">
      <video id="h-video" width="320" height="240" autoplay loop>
        <source src="../static/h.mp4" type="video/mp4">
      </video>
    </a>

   <audio id="h-sound">
    <source src="../static/h.mp3" type="audio/mpeg">
   </audio>


   <a href="https://www.google.com/" id="s-link" class="s-swoosh">
      <video id="s-video" width="320" height="240" autoplay loop>
        <source src="../static/s.mp4" type="video/mp4">
      </video>
   </a>

   <audio id="s-sound">
     <source src="../static/s.mp3" type="audio/mpeg">
   </audio>

JS:

hSound();
sSound();



function hSound() {

 var links = document.getElementsByClassName('h-swoosh'),

 audio = document.getElementById('h-sound'),

 clickHandler = function(event) {
  var href = this.href; // cache href here

 event.preventDefault();
 event.stopPropagation();

 audio.play();

 audio.addEventListener('ended', function(){
   window.location = href; // use cached href here
 })
};

for (var i in links) {
links[i].addEventListener('click', clickHandler, true, true);
}

};



function sSound() {

var links = document.getElementsByClassName('s-swoosh'),

audio = document.getElementById('s-sound'),

clickHandler = function(event) {
 var href = this.href; // cache href here

 event.preventDefault();
 event.stopPropagation();

 audio.play();

 audio.addEventListener('ended', function(){
   window.location = href; // use cached href here
})
};

for (var i in links) {
 links[i].addEventListener('click', clickHandler, true, true);
}

};

Any help would be immensely appreciated.

about 4 years ago · Juan Pablo Isaza
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