How can I get the local Storage Value
html, javascript, local-storage
Solution
Your code should be :
var cookieValue = document.getElementById("demo");
var value = cookieValue .getAttribute('value');
if(typeof(Storage)!=="undefined")
{
alert(value);
localStorage.setItem("GetData" , value);
alert(localStorage.getItem("GetData"));
}
function loading()
{
alert("coming");
var allcookies = localStorage.getItem('GetData');
alert(allcookies);
}
OR
var cookieValue = document.getElementById("demo");
var value = cookieValue .getAttribute('value');
if(typeof(Storage)!=="undefined")
{
alert(value);
localStorage["GetData"] = value;
alert(localStorage["GetData"]);
}
function loading()
{
alert("coming");
var allcookies = localStorage["GetData"];
alert(allcookies);
}
Problem
``` var cookieValue = document.getElementById("demo"); var value = cookieValue .getAttribute('value'); if(typeof(Storage)!=="undefined") { alert(value); localStorage.setItem = ("GetData" , value); alert(localStorage.setItem); } function loading() { alert("coming"); var allcookies = localStorage.getItem('GetData'); alert(allcookies); } ``` Above is the way I am setting `localStorage.setItem` and I am getting LocalStorage. But Where I didn't get the output it is showing Null. Please Suggest me any Solution.