Написал вот такой код. Не работает. Подскажите что исправить.
var video = document.getElementById("video");
var volume = document.getElementById("volume");
volume.onclick = function() {
if (video.hasAttribute('muted')) {
video.removeAttribute('muted');
} else {
video.addAttribute('muted');
}
};
<video id="video" autoplay loop muted>
<source src="img/video.mp4" type="video/webm" />
</video>
<button id="volume">Звук</button>