-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathjson.js
More file actions
36 lines (31 loc) · 990 Bytes
/
json.js
File metadata and controls
36 lines (31 loc) · 990 Bytes
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
fetch('https://restcountries.com/v2/all')
.then(response => response.json()) // converting response into json
.then(data => jasonData(data));
function jasonData(data)
{
// console.log(data)
for (let i of data)
{
let createdDiv = document.createElement('div')
createdDiv.classList.add('country-list-div')
createdDiv.innerHTML = `
<h1>${i.name}</h1>
<button onclick="details('${i.name}')">Know more</button>`
let section = document.getElementById('country-section-id')
section.appendChild(createdDiv)
}
}
function details(countryName)
{
// console.log('clicked')
fetch(`https://restcountries.com/v2/name/${countryName}`)
.then(res => res.json())
.then(data => detailsUI(data))
}
function detailsUI(data)
{
let infoSection = document.getElementById('info')
infoSection.innerHTML =
`<h1>${data[0].name}</h1>
<img width="100px" src='${data[0].flag}' alt="">`
}