S
S
Sergey Goryachev2017-04-03 16:35:09
css
Sergey Goryachev, 2017-04-03 16:35:09

How to set a cookie when a link is clicked (jQuery)?

There is a link, when you click on it, the style of the block changes (a class is added).
Accordingly, it should work on the entire site until the browser is closed.
How to remember this action in a cookie?

$(".special__link--imgoff").click(function(e){
    $("*:not(.sp_ignored) img").addClass('imgoff');
    e.preventDefault();
});

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
Maxim Timofeev, 2017-04-03
@webirus

And why pull the cookie and then drag it back and forth. I would do this:

$(".special__link--imgoff").click(function(e){
    $("*:not(.sp_ignored) img").addClass('imgoff');
localStorage.setItem("class", "imgoff");
    e.preventDefault();
});

https://www.w3schools.com/html/html5_webstorage.asp

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question