Set to localStorage

localStorage[tovarid] = value; 

How can I display it in a div on my page without reloading the page, immediately, just if I get the value and output, I need to reload the page.

  • one
    If you enter a value in the repository, then at the same time you have a variable with the value that you enter ...... so take the value from the same variable and bullet into the div - Alexey Shimansky
  • So I did, but I wonder if it is possible right away - zkolya
  • @zkolya, what did, and why do you think that it is not immediately - Grundy
  • @zkolya it works right away anyway ... it's not cookies .... as an example: localStorage.setItem('test', 'myTestValue'); console.log(localStorage.getItem('test')) localStorage.setItem('test', 'myTestValue'); console.log(localStorage.getItem('test')) - immediately displays the value of the test key that you entered before the output ..... can you have before the reboot and the values ​​you don’t have that you are trying to deposit in the repository? - Alexey Shimansky

1 answer 1

localStorage works regardless of page reload. The only thing that will prevent getting the value stored in localStorage is closing the browser. PS Do not confuse localStorage with sessionStorage .

  • I nakosyachil, deduced values ​​when loading the document, and at the time of adding did nothing. - zkolya