I have some a JS function written to change bg image via a button click, and then back to the original bg when button clicked again. Below is my JS.
const nextBackgroundImageUrl = {
"url('../images/pexels_bg.jpeg')": "url('/images/bbyshrk.jpg')",
"url('../images/bbyshrk.jpg')": "url('/images/pexels_bg.jpeg')"
}
function changeImg() {
const currentBackgroundUrl = document.body.style.backgroundImage;
console.log("current bg url:" + currentBackgroundUrl);
document.body.style.backgroundImage = nextBackgroundImageUrl[currentBackgroundUrl];
}
In the console.log I get nothing after "Current bg url", therefore currentBackgroundUrl isn't grabbing the bg image. Am I using the wrong style property to grab the img? I need the URL.
Thank you!