forked from Shoytanbaba99/learning-web-development
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
22 lines (19 loc) · 681 Bytes
/
script.js
File metadata and controls
22 lines (19 loc) · 681 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
const btn = document.getElementById("loadBtn");
const container = document.getElementById("feedContainer");
btn.addEventListener("click", async ()=> {
const response = await fetch("https://jsonplaceholder.typicode.com/posts");
const data = await response.json();
container.innerHTML = "";
const top5 = data.slice(0,5);
top5.forEach(post =>{
const card = document.createElement("div");
card.style.border = "1px solid #333";
card.style.margin = "10px";
card.style.padding = "10px";
card.innerHTML = `
<h3>${post.title}</h3>
<p>${post.body}</p>
`;
container.appendChild(card);
});
});