jquery - Maintain state of page after refresh -


i'm tryiing save state of page load div onclick function. when click on link page loaded div correctly when refresh page lose content , have click again load

<script language="javascript">   $(document).ready(function () {     $('#foo').click(function () {         $('#bar').load('news.asp');          localstorage.setitem('display', $(this).siblings().is(':visible'));     });     var block = localstorage.getitem('display');     if (block == 'true') {         $('#bar').show()     } });  </script> 

html

<div id="bar"></div> 

you need store content in localstorage, not result of .is(':visible').

you need append content #bar when page refreshes:

$(document).ready(function () {     $bar = $('#bar');     $('#foo').click(function () {         $bar.load('news.asp');         localstorage.setitem('display', $bar.html());     });      var block = localstorage.getitem('display');     if (block !== null) {         $bar.html(block).show()     } }); 

Comments

Popular posts from this blog

Email notification in google apps script -

c++ - Difference between pre and post decrement in recursive function argument -

javascript - IE11 incompatibility with jQuery's 'readonly'? -