1

I hope this is a simple question, but can't find it covered elsewhere.

I simply want check for the presence of a cookie - if it's there, do nothing, but if it's not there, replace the content of a particular div (I think I know how to do this last bit.

Any ideas?

Matthew
  • 35
  • 4

2 Answers2

0

You may read it like var cookieValue = $.cookie("test"); And check the cookieValue if is empty.

Check this answer for more details how to work with cookies: How do I set/unset cookie with jQuery?

Community
  • 1
  • 1
dotmindlabs
  • 778
  • 1
  • 12
  • 35
0

you can check cookie existence at server side before rendering page. you will get all cookie details in request object
If your cookie not there,then replace the content of a particular div in server side
otherwise you can check in client side as below,
if (jQuery.cookie('cookietitle')) { // Reactions }

Jameel Grand
  • 2,294
  • 16
  • 32
  • Sorry I meant to explain that this was the code I've currently got - not working though. (I'm very much new to this, as you can see ... $(document).ready(function() { var moodle_cookie = $.cookie("MoodleSession"); if (moodle_cookie = null) $("div#cycle-content").each (function(){ $(this).replaceWith("

    Access to this content requires a valid University of Nottingham Moodle login

    "); }); });
    – Matthew Mar 13 '15 at 12:45