I'm trying to save the state of a checkbox using sessionStorage. I'm quite new to JavaScript so my understanding is pretty basic.
I'm using a checkbox on a website to display the navigation menu. This checkbox is present on each page of the website (same id). The aim of saving the checkbox state is to have the navigation menu already "open" when a new page is navigated to. Currently the menu "jumps" closed upon page changes and defeats the purpose of the CSS transition effect.
Any help is greatly appreciated.
Thanks
This is what I've got so far (content butchered from around the web).
JS:
<script type="text/javascript">
function checkFunction(){
var checkbox = document.getElementById("nav-btn");
checkbox.addEventListener("onChange",OnChange,false);
}
function save(){
var nav-btn=document.getElementById("nav-btn").value;
sessionStorage.setItem(nav-btn);
}
window.addEventListener("load",checkFunction,false);
</script>
HTML:
<input type="checkbox" id="nav-btn" class="nav-btn" />
<label for="nav-btn"></label>
Aucun commentaire:
Enregistrer un commentaire