-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfavourites.html
78 lines (74 loc) · 2.22 KB
/
favourites.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Favourites</title>
<link rel="stylesheet" href="style.css" />
<!-- <script src="./script.js" defer></script> -->
<style>
@import url("https://fonts.googleapis.com/css2?family=Dancing+Script:wght@700&display=swap");
</style>
</head>
<body>
<nav class="nav-bar">
<div class="right">
<div class="logo"></div>
<div class="name">
<a
href=""
style="font-size: 25px; font-family: 'Dancing Script', cursive"
>Superhero</a
>
<a href="">Hunter</a>
</div>
<div id="pop-up" class="pop-up">pop-up sample</div>
</div>
<ul class="left">
<a href="index.html">Home</a>
<a href="favourites.html">Favourites</a>
</ul>
</nav>
<!-- -->
<main class="mainIndex fav-index">
<!-- <div class="fav-card">
<img src="./images/logo.png" alt="" />
<button id="heart">♡</button>
<h2>Name</h2>
</div> -->
</main>
</body>
<script>
const card = document.querySelector(".fav-index");
const popUp = document.getElementById("pop-up");
// console.log(localStorage.favList);
function getData() {
let list = [];
if (localStorage.favList) {
list = JSON.parse(localStorage.favList);
}
card.innerHTML = "";
if (list.length > 0) {
list.map((element, i) => {
id = element.id;
card.innerHTML += `<div class="fav-card">
<img src="${element.image.url}" alt="" />
<button onclick="handelHeart(${id});" id="heart">❤️️</button>
<h2>${element.name}</h2>
</div>`;
});
}
}
function handelHeart(ref) {
console.log("id", ref);
let list = JSON.parse(localStorage.favList);
// console.log(list);
const newList = list.filter((element) => element.id != ref);
// console.log(newList);
localStorage.setItem("favList", JSON.stringify(newList));
getData();
}
getData();
</script>
</html>