This is how to use cookies. The CodePen link is here. First you want to make a function that retrieves the text from a input field and stores it in a cookie. You can call it whatever you want, but I called it "show".

//Store the text in the input as a "show" cookie

localStorage.setItem("show", te.value)

"te" is my text input. And I used .value to make sure I am getting the value of te. Not any other data. Now that you have stored the data, you want to retrieve the data. For that I will make the div a variable in JavaScript. First I will create a function that checks the cookie when the page loads. I will use this.

window.onload = function(){load();};

When the window loads then the function triggers. In the function we need to set the innerHTML of the div to the cookie data.

div.innerHTML = localStorage.getItem("show");

This function make the div's innerHTML of the show cookie. Now refresh the page and what you entered will be right in front of you. Try it yourself.

2,367 0 3