I have a button on an accessibility bar, which when clicked calls the following function:
function contraste2 ()
{
var css = document.querySelector('#css');
var contraste = Cookies.get("contraste");
if (contraste == "contrasteinativo" || contraste =="undefined")
{
Cookies.set("contraste","contrasteativo", { expires: 365 });
css.setAttribute('href', 'estiloscontraste.css');
}
if (contraste == "contrasteativo")
{
css.setAttribute('href', 'estilos.css');
Cookies.set("contraste","contrasteinativo", { expires: 365 });
}
}
The application of the contrast css is by means of an alternative css, called in the function.
But this code is wrong, I know.
If the contrast has not yet been applied (cookie = undefined), then it activates the contrast and sets the cookie to active.
But soon after, it checks to see if the cookie is active, and if it does, it turns off the contrast. That way, it turns out that there is no change in the page (since the cookie will always be inactive).
I am not able to create a logic for this, I thought to make a kind of accountant to check if the button was already clicked, one accountant through another cookie.