Skip to content

Instantly share code, notes, and snippets.

@lcloss
Created December 8, 2023 14:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lcloss/784a49254fbedfe0b5b1268b3c68bf88 to your computer and use it in GitHub Desktop.
Save lcloss/784a49254fbedfe0b5b1268b3c68bf88 to your computer and use it in GitHub Desktop.
Elementor toggle sound button
<script>
document.addEventListener('DOMContentLoaded', function() {
var toggleSoundButtonMuted = document.querySelector('.e-fas-volume-mute');
var toggleSoundButtonSound = document.querySelector('.e-fas-volume-up');
toggleSoundButtonSound.style.display = "none";
var iconWrapper = toggleSoundButtonMuted.closest('.elementor-icon');
var secondIconWrapper = toggleSoundButtonSound.closest('.elementor-icon');
secondIconWrapper.removeChild(toggleSoundButtonSound);
var heroBackgroundVideo = document.querySelector('.herosection video');
toggleSoundButtonMuted.addEventListener('click', function (event) {
if (heroBackgroundVideo.muted !== false){
heroBackgroundVideo.muted=false;
iconWrapper.removeChild(toggleSoundButtonMuted);
iconWrapper.appendChild(toggleSoundButtonSound);
toggleSoundButtonSound.style.display = "block";
toggleSoundButtonMuted.style.display = "none";
} else {
heroBackgroundVideo.muted=true;
iconWrapper.removeChild(toggleSoundButtonSound);
iconWrapper.appendChild(toggleSoundButtonMuted);
toggleSoundButtonSound.style.display = "none";
toggleSoundButtonMuted.style.display = "block";
}
});
toggleSoundButtonSound.addEventListener('click', function (event) {
if (heroBackgroundVideo.muted !== false){
heroBackgroundVideo.muted=false;
iconWrapper.removeChild(toggleSoundButtonMuted);
iconWrapper.appendChild(toggleSoundButtonSound);
toggleSoundButtonSound.style.display = "block";
toggleSoundButtonMuted.style.display = "none";
} else {
heroBackgroundVideo.muted=true;
iconWrapper.removeChild(toggleSoundButtonSound);
iconWrapper.appendChild(toggleSoundButtonMuted);
toggleSoundButtonSound.style.display = "none";
toggleSoundButtonMuted.style.display = "block";
}
});
});
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment