Skip to content

Commit 7a75e4b

Browse files
committed
add basic styling for post tile
1 parent a7daa00 commit 7a75e4b

File tree

2 files changed

+22
-4
lines changed

2 files changed

+22
-4
lines changed

index.html

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,32 @@
66
<title>Document</title>
77
</head>
88
<style>
9+
* {
10+
margin: 0;
11+
padding: 0;
12+
box-sizing: border-box;
13+
}
14+
915
body {
16+
padding: 1rem;
1017
display: grid;
1118
place-items: center;
1219
}
20+
21+
.post {
22+
margin: 1rem;
23+
padding: 1rem;
24+
border: 0.125rem solid black;
25+
}
26+
27+
h1 {
28+
padding: 1rem;
29+
}
1330
</style>
1431
<body>
1532
<button id="fetch-api-button">Click To Fetch</button>
33+
<h1>API Titles</h1>
1634
<div class="append-titles">
17-
<h1>API Titles</h1>
1835
</div>
1936

2037

script.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,19 +20,20 @@ async function fetchTodo(apiUrl) {
2020
function appendData(data) {
2121
const container = document.querySelector('.append-titles');
2222
data.forEach((item) => {
23-
const newTitle = document.createElement('span');
23+
const newTitle = document.createElement('div');
24+
newTitle.className = 'post';
2425
newTitle.innerHTML = item.title;
2526
container.appendChild(newTitle);
2627
});
2728
}
2829

2930
// Helper function to store data from fetch function and pass on to appendData function
30-
const getData = async () => {
31+
async function clickHandler() {
3132
const data = await fetchTodo(postApi);
3233
appendData(data);
3334
}
3435

3536
window.onload = () => {
3637
const button = document.getElementById('fetch-api-button');
37-
button.addEventListener('click', getData);
38+
button.addEventListener('click', clickHandler);
3839
}

0 commit comments

Comments
 (0)