I have one html page 1.html
and i want to get some text content and store it to a js.js
file using jquery to get the text by id.
This code only works in 1.html
page, where the text I want to copy from is but not in 2.html
file.
Here is my code. Note that it works if I store text inside localstorage setter second parameter.
$( document ).ready(function() {
var c1Title= $('#r1c1Title').text();
//changing c1Title to any String content like "test" will work
localStorage.setItem("t1",c1Title);
var result = localStorage.getItem("t1");
$("#title1").html(result);
alert(result);
});
Here is the complete demo I am working on Github: