execute only if element is on page

This commit is contained in:
Jonas Leder 2021-03-24 23:50:10 +01:00
parent eb36eb4ba3
commit 8e1d48dc66
2 changed files with 22 additions and 14 deletions

View file

@ -1,5 +1,9 @@
document.querySelector("#burgerMenu").onclick = () => {
document.getElementById("burgerMenu").classList.toggle("change");
document.getElementById("mainMenuContainer").classList.toggle("visible");
let burgerMenu = document.querySelector("#burgerMenu");
if(burgerMenu != null) {
burgerMenu.onclick = () => {
document.getElementById("burgerMenu").classList.toggle("change");
document.getElementById("mainMenuContainer").classList.toggle("visible");
}
}

View file

@ -10,15 +10,19 @@ function getCookie(name){
return null
}
let cookieInfo = document.querySelector(".cookieinfo");
if (getCookie("cookieMessageHide") === "1"){
cookieInfo.style.display = "none";
} else {
cookieInfo.style.display = "block";
}
document.querySelector(".cookieinfo-close").onclick = function() {
console.log("close");
document.cookie = "cookieMessageHide=1";
cookieInfo.style.display = "none";
}
let cookieInfo = document.querySelector(".cookieinfo");
if(cookieInfo != null) {
if (getCookie("cookieMessageHide") === "1") {
cookieInfo.style.display = "none";
} else {
cookieInfo.style.display = "block";
}
document.querySelector(".cookieinfo-close").onclick = function() {
console.log("close");
document.cookie = "cookieMessageHide=1";
cookieInfo.style.display = "none";
}
}