<Audio src="music.mp3"></audio>
<Audio src="music2.mp3"></audio>
<audio id="audio1" src="music.mp3"></audio>
<audio id="audio2" src="music2.mp3"></audio>
const audioElements = Array.from(document.getElementsByTagName('audio'));
const stopOtherAudio = (currentAudio) => {
audioElements.forEach((audio) => {
if (audio !== currentAudio) {
audio.pause();
audio.currentTime = 0;
}
});
};
audioElements.forEach((audio) => {
audio.addEventListener('play', () => stopOtherAudio(audio));
});