Skip to content Skip to sidebar Skip to footer

How To Keep Button State Across Different Pages?

When I do a click, I assign a disabled attribute to the button: $('.save_post').on('click', function() { $(this).attr('disabled', 'true'); }); However, if I change page and th

Solution 1:

Just assign an ID to each .save_post element:

<button id="savePost1" class="save_post">Save Post</button>

And then reference the ID:

$('.save_post').on('click', function() {
    $(this).attr("disabled", "true");
    localStorage.setItem('saveButton', $(this).attr('id'));
});

And then call it on load:

$('#'+localStorage.getItem('saveButton')).attr('disabled', true);

Post a Comment for "How To Keep Button State Across Different Pages?"