Home > Net >  why isn't my button to delet the local storage working
why isn't my button to delet the local storage working

Time:10-07

I have a button, if he gets klicked it should delet the item "monday" in local storage but it isn't workin can someone help me?

html:

 <form  onsubmit="reset(); return false">
        <button>Löschen</button>
    </form>

js:

function reset() {
    localStorage.removeItem("monday");
}

CodePudding user response:

Problem you have is form has a reset method and that is what is being triggered. You can see that when you add a text field. Add some text and submit and you see the text removed.

<form  onsubmit="reset(); return false">
  <input type="text">
  <button>Löschen</button>
</form>

Solution, rename your function

function resetStorage(){
  console.log('called');
}
<form  onsubmit="resetStorage(); return false">
  <button>Löschen</button>
</form>

  • Related