jQuery Data Type How to - Get and set value for cookie








Question

We would like to know how to get and set value for cookie.

Answer


<!DOCTYPE html>
<html>
<head>
<script type='text/javascript'
  src='http://code.jquery.com/jquery-1.10.1.js'></script>
<script type='text/javascript'
  src="http://cdnjs.cloudflare.com/ajax/libs/jquery-cookie/1.3.1/jquery.cookie.min.js"></script>
<script type='text/javascript'>
$(function(){<!--  ww w . j  ava 2  s  .c o m-->
if ($.cookie('test_status') != '1')
{
    setTimeout(function()
    {
        console.log('foo');
        jQuery.cookie('test_status', '1', { expires: 31}); 
    }, 1000);
}
});
</script>
</head>
<body>
</body>
</html>

The code above is rendered as follows: