Tell me how to implement the following mechanism There is a link by clicking on which we get the text values of the span from the parent unit with the name class and price_per_unit . And then the cookie check whether the value matches the text value of the span with the name class, if there is, then delete this value from the cookie. Cook has the following structure
basket1: "["Текст","860"]" basket2 "["Книга","160"]" To work with the cookie using trace. library https://github.com/js-cookie/js-cookie
$(document).on("click",".del", function(e){ e.preventDefault(); var removeProduct = $(this).closest(".block").find("span.name").text(); var removePrice = $(this).closest(".goods").find("span.price_per_unit").text(); $(this).closest(".goods").hide(); obj = document.cookie; for (var prop in obj) { if(obj == removeProduct) { obj = null; } } });
$.cookie("name", null, { path: '/' })or so$.removeCookie('name', { path: '/' });? Not? - Yuri