0

this question, there is a script for a button that, when pressed, is replaced by another and back, but can not figure out how to write code to memorize what is currently visible and what is not. I understand that it is necessary to write in localstorage, many similar examples, but the appropriate code for I can not find. Can anyone help with writing a couple of lines? I would be very grateful)) His attempts to rewrite existing code by itself does not see the point, I will lay out the current to switch the buttons:

$(".close_button").click(function(e){
    e.preventDefault(); 
    $(".min_button").fadeIn(500);
    $(".minification").css("display","none");
});
$(".min_button").click(function(e){
    e.preventDefault();  
    $(".minification").fadeIn(500);
    $(".min_button").css("display","none");
});
Webear
  • 63
  • 6
  • I know i need to use localstorage function, but I not know js well – Webear Dec 22 '16 at 04:15
  • why you need localStorage? I think not. If you want to know what button is visible just check the display attribute of both, or add a css class like `visible` to easy identify the visible button. –  Dec 22 '16 at 04:16
  • Possible duplicate of [Use HTML5 localstorage to retain jQuery toggle state on page refresh](http://stackoverflow.com/questions/22830004/use-html5-localstorage-to-retain-jquery-toggle-state-on-page-refresh) – Klinger Dec 22 '16 at 04:17
  • See [Global Variable usage on page reload](http://stackoverflow.com/questions/29986657/global-variable-usage-on-page-reload), [Toggle URL parameter with button](http://stackoverflow.com/questions/31765968/toggle-url-parameter-with-button) – guest271314 Dec 22 '16 at 04:45

1 Answers1

0

If you want to use local storage you can use a cookie. You would have to set the cookie in the event functions and then call them if the cookie is set.

It might look something like this but it is untested. To understand it better you could read this response. How do I set/unset cookie with jQuery?

if ($.cookie("close_button") == "true") {
    close_buttonClick()
}
if ($.cookie("min_button") == "true") {
    min_buttonClick()
}
$(".close_button").click(close_buttonClick);
$(".min_button").click(min_button);
function close_buttonClick(e){
    if (e) e.preventDefault(); 
    $(".min_button").fadeIn(500);
    $(".minification").css("display","none");
    $.cookie("close_button","true")
    $.cookie("min_button","false")
}
function min_buttonClick(e){
    if (e) e.preventDefault();  
    $(".minification").fadeIn(500);
    $(".min_button").css("display","none");
    $.cookie("min_button","true")
    $.cookie("close_buton","false")
}
Community
  • 1
  • 1
B Roy Dawson
  • 611
  • 1
  • 6
  • 18