I have a login page and I am storing the localStorage key’s value i.e. username taken from login page to a variable using var unameVar=localStorage.getItem('uname')
. Now I want to assign the value of unameVar
to a button. To put it short the button’s name should be that of unameVar
on page load. Need help on this
javascript
<script>
var unameVar=localStorage.getItem('uname');;
console.log(unameVar)
</script>
html
<button class="btn btn-link" > This value needs to be changed
</button>
2
Answers
Just call onload function and pass the new value from
localStorage
.Add an
id
to the button then after retrieving value from localStorgae, usetext
from jquery library to add text