I want to use vanilla js in my project. I have some functions, and I have problem with one of them. The idea of script is: click link on main page, which redirects to other page; add class to #div1. When I click a link and I'm redirecting to other page - nothing hepens. I can't find I do wrong.
HTML from main page:
<a href="pagelink" id="view">text</a>
HTML from other page:
<div class="row" id="div1"></div>
<div class="row" id="div2"></div>
JS
window.onload = function () {
var hideDivOne = document.getElementById("div1"),
View = document.getElementById("view");
function swap() {
hideDivOne.className += " notdisplayed";
}
if(View){
View.addEventListener("click", swap, false);
}
}
CSS
.notdisplayed {display:none;}