I am trying to make a popup appear on a webpage only once, using Javascript.
So on page load, I create a cookie. Then I have an if statement - if the cookie has already been made, I don't wish to display the popup - so I am fading it out. (Is there a better way to just make this not appear at all?)
I have created a codebox here.
JS here, both areas it is targetting are simple divs :
$(document).ready(function(){
var visited = $.cookie('visited'); // create the cookie
if (visited == 'yes') {
$("#popup").fadeOut();
$("#popup").fadeOut();
}
else
{
$("#hover").click(function(){
$(this).fadeOut();
$("#popup").fadeOut();
});
$("#close").click(function(){
$("#hover").fadeOut();
$("#popup").fadeOut();
});
$.cookie('visited', 'yes', {
expires: 7 // the number of days the cookie will be effective
});
}
});
Unfortunately, none of the Javascripts seems to run - the popup will no longer close or recognize clicks and displays every time the user navigates to the page.
What have I done incorrectly here and how can I fix it ?
$("#popup").fadeOut();lines - one of them probably shouls be #hover, but we need to see the html part for a better answer