I have multiple localstorage values that I want to write in the HTML code.
My main div
name is data
and there is an h2
tag inside that div
<div id="data">
<h2></h2>
</div>
Now if i want to write the value of my localStorage
to the data
div i would do this,
document.getElementById("data").innerHtml = localStorage.score;
but I want to write it inside the h2
tag,
So i tried this after searching on Stackoverflow,
document.getElementById("data").getElementsByTagName('h2').innerText = localStorage.score;
and this,
document.getElementById("data").getElementsByTagName('h2').firstChild.nodeValue = localStorage.score;
but both of these are not working. Why it is not working can anybody tell me ?