samedi 6 juin 2015

Using cookie.js here, but can't get if statement right with Jquery. What I have so far:

I've been unable to figure out the right way to implement this mainly because of syntax issues as I'm fairly new to all of this.

So, I'm checking to see if a user has been to a certain page (Page2). On Page2 I've got this script:

$.cookie('visitPage2', true, { expires: 365 });

Back on my homepage I'm running this script to change an image from displaying a lock to displaying the actual image instead. (but I know my syntax isn't right):

if (!$.cookie('visitPage2')){
$( ".swap" ).toggleClass( "lock unlock" );

I had previously checked to see if my toggleClass was by just testing it with a click instead of uploading to the server to test cookies and it worked perfectly:

$( ".swap" ).click(function() {
$( ".swap" ).toggleClass( "lock unlock" );
});

Any help is much appreciated! Thanks!

(Just a quick summary in case I have been too wordy. I want to check if a user has been to Page2. If they have I want the homepage to display a new image instead of the usual lock image, which is changed using toggleClass)

Cookie.js documentation is here: http://ift.tt/1HQQ8iq

Aucun commentaire:

Enregistrer un commentaire