Here is my code
$('.sort').click(function(){
console.log($(this).attr('id'));
$.cookie('sortby', $(this).attr('id'), { expires: 25 });
//window.location.reload(true);
});
HTML
<button id="name" class="sort">Name</button>
<button id="price" class="sort">Price</button>
<button id="popular" class="sort">Popularity</button>
My cookie ends up empty and the console shows up as
popular
(an empty string)
It seems it is getting the correct id but then changing it to null
Any suggestions?
In your second call the $(this) object has changed scope. The following should work: