How can I set/store cookie when anchor clicked

Posted by Unaverage Guy on Stack Overflow See other posts from Stack Overflow or by Unaverage Guy
Published on 2012-10-08T02:57:58Z Indexed on 2012/10/08 3:37 UTC
Read the original article Hit count: 149

Filed under:
|

I am trying to use Cookie so that a default style OR a specific style is applied in reference to the anchor tag clicked, even when the browser is closed/reopen. So if the user clicked the second link, close or refresh the browser and reopen, than the style should still be active, if it is their first time the default should apply. This is a little over my turf.

Here is the HTML:

<a id="default" href="#/">Default Style</a>
<a id="style2"  href="#/">Style 2</a>
<a id="style3"  href="#/">Style 3</a>

<ol>
<li><span>Hello World</span></li>
</ol>

JQuery: (Compliments of StackOverflow)

<script type="text/javascript">
$('#default').on('click',function(){
    $('ol li span').removeClass(function() {
          return $(this).attr('class');
        }).addClass('default');
});
$('#style2').click(function(){
    $('ol li span').removeClass(function() {
          return $(this).attr('class');
        }).addClass('style2');
});
$('#style3').click(function(){
    $('ol li span').removeClass(function() {
          return $(this).attr('class');
        }).addClass('style3');
});
</script>

CSS:

<style type="text/css">
.default{
color: #333;
}

.style2{
color: #999;
}

.style3{
color: #800;
}
</style>

© Stack Overflow or respective owner

Related posts about JavaScript

Related posts about jQuery