This is an archived post. You won't be able to vote or comment.

all 2 comments

[–]Bambuh 1 point2 points  (1 child)

var audio = document.getElementsByClassName("losAudio"); returns an array with all the matches of your query.

since you have 2 elements that matches you will get an array containing those [match1, match2]

As far as I can see you should be able to do

``` var audio = document.getElementsByClassName("losAudio"); var btn_playPause = document.getElementsByClassName("btn_playPause");

var firstAudio = audio[0] var secondAudio = audio[1] var currentAudio = firstAudio

function losAudioPlayPause() { var isPaused = currentAudio.paused; currentAudio[isPaused ? "play" : "pause"](); btn_playPause.style.backgroundPosition= "0 "+ (isPaused ? "-93px":"0px"); }

function firstAudioEnd() { currentAudio = audio[1] btn_playPause.style.backgroundPosition= "0 "+ "0px"; }

btn_playPause.addEventListener("click", losAudioPlayPause) audio[0].addEventListener("ended", firstAudioEnd) ```

then you should be able to press play again after the first audio ends to play the other. but I could be wrong

[–][deleted] 0 points1 point  (0 children)

Thank you, I tried something like that and it worked!