On clicking, the url must change, and the image as well. I lost about 6h of my life to find a solution but now I'm here. Could anyone help...
/*
-----------------------------------------
Right-top sound box
-----------------------------------------
*/
function init() {
let rtsb = document.querySelector('#backSound');
function changeSound() {
// changing sound image:
let url1 = "url('https://cdn.glitch.com/00f52d97-70e5-4e02-98af-d0b48468a631%2FsoundOn1.jpg?v=1595501327338')";
let url2 = "url('https://cdn.glitch.com/00f52d97-70e5-4e02-98af-d0b48468a631%2FsoundOff2.jpg?v=1595501337285')";
let imSrc = rtsb.style.backgroundImage;
imSrc = url1;
if (imSrc === url1) {
imSrc = url2;
} else if (imSrc === url2) {
imSrc = url1;
}
}
rtsb.addEventListener('click', changeSound);
}
document.addEventListener('readystatechange', function() {
if (document.readyState === "complete") {
init();
}
});
<div id="backSound" style="height:200px"></div>