On the top right corner of my image gallery, there's a button that, when clicked, creates an overlay darkening the image. I'm trying to figure out how to toggle this effect on and off with a click. Any suggestions on how I can achieve this?
Here is the code snippet I am currently using:
btn.addEventListener("click", ()=> {
var btnClass = btn.getAttribute("class");
if(btnClass === "dark") {
overlay.backgroundColor = "rgba(0,0,0,0.5)";
btn.textContent = "Lighten";
btn.setAttribute("class", "light");
} else if (btn.className != "dark") {
overlay.backgroundColor = "rgba(0,0,0,0)";
btn.textContent = "Darken";
btn.setAttribute("class", "dark");
}
})