I am creating a song book app with 'add to favorite' button. i have song1.html song2.html and favorite.html.
in song1.html, when add to favorite button is clicked. i am storing the link to that song in local storage.
This is my song1.html
<!DOCTYPE html>
<html>
<body>
<button onclick=mySongOne()>add to favorite</button>
<script>
function mySongOne() {
localStorage.setItem(favsong, <a href='https://www.song1.com'><h1>song1</h1></a>);
}
</script>
</body>
</html>
in song2.html, when add to favorite button is clicked. i am storing the link of the second song in local storage.
song2.html
<!DOCTYPE html>
<html>
<body>
<button onclick=mySongTwo()>add to favorite</button>
<script>
function mySongTwo() {
localStorage.setItem(favsong, <a href='https://song2.com'><h1>song2</h1></a>);
}
</script>
</body>
</html>
now i have a favorite.html for listing my favourite songs. and favourite.html will retrieve the links that i stored in local storage.
favorite.html
<!DOCTYPE html>
<html>
<body onload=myFunction()>
<div id=result></div>
<script>
function myFunction() {
document.getElementById(result).innerHTML = localStorage.getItem(favsong);
}
</script>
</body>
</html>
Now i want to show both song 1 and song 2 in favorite.html.
but only song 2 is displayed in favourite.html. How to accomplish this.