claudios claudios - 1 year ago 87
jQuery Question

Save current state after jquery click function

I am trying to hide a button after clicking another button but as when the page refreshed, the hidden button shows up again. I wanted to remain it hidden even if I refresh the page and show it only if I click the show button.
Any help would be much appreciated.


<button type="button" class="showhide">Show / Hide</button>
<button type="button" class="link">Link</button>



Answer Source

Like @Kartikeya said, use localStorage.

Set it when you click the button. On page load check the value of the localStorage to update the visibility of the button.


    var isVisible = $('.link').is(":visible"); 
    localStorage.setItem('visible', isVisible);

// stored in localStorage as string, `toggle` needs boolean
var isVisible = localStorage.getItem('visible') === 'false' ? false : true;

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download