music1 / audio.js
JAYASWAROOP's picture
Update audio.js
de7f03e
raw
history blame
854 Bytes
document.addEventListener('DOMContentLoaded', function () {
const movieContainers = document.querySelectorAll('.movie');
movieContainers.forEach(function (container) {
container.addEventListener('click', function () {
const audio = this.querySelector('audio');
// Hide all other audio elements except the one clicked
movieContainers.forEach(function (otherContainer) {
const otherAudio = otherContainer.querySelector('audio');
if (otherAudio !== audio && !otherAudio.paused) {
otherAudio.pause();
otherAudio.classList.add('d-none'); // Hide other audio elements
}
});
// Toggle the display class of the audio element
audio.classList.toggle('d-none');
if (audio.paused) {
audio.play();
} else {
audio.pause();
}
});
});
});