I want to create a cookie which will remember a product that costumer wants to add to wish list. Every product and button which is named heart in code has its specific array value which is f. For some reason this code doesnt create a cookie:
var hearts=document.getElementsByClassName("heart");
var f;
for(f=0;f<heart.length;f++) {
hearts[f].addEventListener("click",function(){setCookie(f);});
}
function setCookie(f){
var d=new Date();
d.setTime(d.getTime() + 365*24*60*60*1000);
var expires="expires="+d.toUTCString();
document.cookie="product="+f+";"+domain=localhost+expires+";path=/";
}