-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfetch.js
More file actions
45 lines (33 loc) · 1.08 KB
/
Copy pathfetch.js
File metadata and controls
45 lines (33 loc) · 1.08 KB
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
let fetchData;
let button = document.querySelector(".search-button");
let container= document.querySelector(".container");
let boxcontainer = document.querySelector(".box-container");
let searchInput = document.querySelector(".search-bar");
let box = document.querySelector(".box")
let searchVariable;
async function fetchapi() {
let fetchPromise = await fetch("https://jsonplaceholder.typicode.com/posts");
fetchData = await fetchPromise.json()
console.log(fetchData)
}
fetchapi()
function handleSearch(){
var searchTerm = searchInput.value
searchVariable = searchTerm
console.log(searchVariable)
}
function preciseid(n) {
box.innerText = JSON.stringify(fetchData[n])
console.log("Precise-id")
}
// document.addEventListener("DOMContentLoaded", function(){
// button.addEventListener("click", function(){
// let div = document.createElement("div");
// div.classList.add("box");
// boxcontainer.appendChild(div);
// })
// })
button.addEventListener('click', () => {
preciseid(searchVariable);
})
//this is what i add in the file