-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
35 lines (32 loc) · 1.15 KB
/
index.js
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
let articleBox = document.getElementById("box");
let list = document.getElementById("list");
fetch(
"https://newsapi.org/v2/everything?q=tesla&from=2022-04-17&sortBy=publishedAt&apiKey=2cec3bee1cc4401699aab2d713ee705e"
)
.then((res) => res.json())
.then((res) => {
const data = res;
console.log(data);
data?.articles?.map((item) => {
let test = document.createElement("li");
test.innerHTML = `
<div class="id">
<div id="news_list">
<img src="${item.urlToImage}" class="urlToImage"></span>
<div class="text_list">
<span class="title">${item.title}</span>
<span class="content">${item.content}</span>
<span class="description">${item.description}</span>
<span class="url">${item.url}</span>
</div>
<div class=under_list">
<hr class="hr">
<span class="author">${item.author}</span>
<span class="publishedAt">${item.publishedAt}</span>
</div>
</div>
</div>`;
console.log(test);
list.appendChild(test);
});
});