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

287
Vistas
How to stop an audio element created by a function? IE: audio = new Audio()

I'm creating a Canvas game and I'm using this to stop all audios:

  document.querySelectorAll("audio").forEach((el) => {
  if (
    el.id === "song1" ||
    el.id === "song2" ||
    el.id === "song3"
  ) {
    el.volume = 0;
    el.pause();
  } else {
    el.currentTime = 0;
    el.volume = 0;
    el.pause();
  }
});

The problem I have is that this stop all the audios within the <head></head> tag in the html file (preloaded ones), but it does not work for audios created dinamically

function soundGo(newAudio, boolean) {
  if (boolean === true) {
    let audio = new Audio(newAudio);
    audio.volume = 0.1;
    audio.play();
} else {
    let audio = new Audio(newAudio);
    audio.volume = 0;
    audio.pause();
}
}

I want to know if it's possible to iterate all the elements created with new Audio(). The querySelectorAll does not the trick, at least in my case (maybe I'm doing it wrong...).

I tried this also: stop dynamically created Audio

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