Set a cookie on navigation item

Set a cookie on navigation item

Hello!

I Think I've Close to a solution but I need help with the final touch of my code.. The thing is that I need to set a cookie on a navigation that is data driven.. the reason is that I want to set a select class because the page reloads after a click. The markup is given and I cannot change that.

<div class="test" id="1">Link 1</div>
<div class="test" id="2">Link 2</div>


The following jQuery set a 'clicked' class on a div I click (that's great), but if I click on a let's say the next div (navigation item) I need to remove the previous clicked class.

Any Idea?

 $('.test').on('click', function() {
      $(this).addClass('clicked');
       var clicked = $('.test.clicked').map(function() {
            return '#' + this.id;
       }).get().join(',');
      $.cookie('MyCookie', clicked);
});





 var MyCookie = $.cookie('MyCookie');
 $(MyCookie).addClass('clicked');