cookies.blade.php
603 Bytes
<script>
// cookies
const cookieItems = document.querySelectorAll(".js-ck");
if (cookieItems.length) {
cookieItems.forEach(item => {
let id = item.dataset.id;
let like = item.querySelector(".like");
let checkLike = function () {
if (like.classList.contains("active")) {
Cookies.set(id, id);
} else {
Cookies.remove(id);
}
}
like.addEventListener("click", () => {
checkLike();
});
if (Cookies.get(id) == id) {
like.classList.add("active");
}
});
}
console.log(Cookies.get());
</script>