Javascript Browser Storage setItem() Method by dot notation

Introduction

You can also set the value by using dot notation (obj.key):

sessionStorage.test1 = "Lorem ipsum";

This example demonstrates how you can get the value of a specified session storage item.

View in separate window

<!DOCTYPE html>
<html>
<body>
<button onclick="createItem()">Create session storage item</button>
<button onclick="myFunction()">Get the item value</button>
<p id="demo"></p>
<script>

function createItem() {//from w  w w.j  a  v  a  2 s. c  o  m
  sessionStorage.test1 = "hello";
}

function myFunction() {
  var x = sessionStorage.test1;
  document.getElementById("demo").innerHTML = x;
}

</script>
</body>
</html>



PreviousNext

Related