javascript - Toggle Visibility - Show/Hide - Remain shown when toogled -


I have a piece of code that works great, but I want to be on the page if clicked on the open To be fresh. East. The user sees a link and then returns to the previous page. The link is an image and the page (div) has a menu of images.

  & lt; Div id = "block1-1" & gt; & Lt; A name = "work" & gt; & Lt; / A & gt; & Lt; A href = "# block1-1" onclick = "toggle_view ('block 1-1');" & Gt; Lieutenant; H2 & GT; Works & lt; / H2 & gt; & Lt; / A & gt; & Lt; / Div & gt; & Lt; Script type = "text / javascript" & gt; Function toggle_view (id) {var e = document.getElementById (id); If (e.style.display == 'block') e.style.display = 'none'; Else e.style.display = 'block'; } & Lt; / Script & gt; Local storage is probably the simplest solution (works only on some browsers).  

Modify your function to include local storage code:

  function toggle_view (id) {var e = document.getElementById (id); If (E.Style. Display == 'block') {e.style.display = 'none'; LocalStorage.setItem ("Show", False); } Else {e.style.display = 'block'; LocalStorage.setItem ("Show" is true); LocalStorage.setItem ("id", e); }};  

Then you will need to include it:

  window.onload = function ({if (localstorage.getItem ("show")} { Var e = localStorage.getItem ("id"); E = document. GetElementById ("e"); E.style.display = 'block'; }}  

Comments

Popular posts from this blog

import - Python ImportError: No module named wmi -

Editing Python Class in Shell and SQLAlchemy -

lua - HowTo create a fuel bar -