I’m trying to make a program that when you visit the site, it shows the div, a button is pressed to hide it, and it isn’t shown again until chrome is closed and reopened.
function check() {
if (sessionStorage.alreadyClicked) {
document.getElementsByClassName('disclaimer-container')[0].style.display = "none";
sessionStorage.alreadyClicked = 1;
}
I’ve tried adding sessionStorage.alreadyClicked
to by code as seen here to no avail.
No matter what I do the div will always show. I’m looking a cross browser solution in the long term but as of now just chrome.
2
Answers
this should work , although I recommend to get the div by id not class because the following function will hide only the first one because of the [0] so you need to make sure that it will always be first at this case. -thank you VLAZ-
From that same page:
“Be careful with sessionStorage because it can only store string values.”
Right now your if statement is essentially checking if that storage exists, which will always return true.
Try this instead: