-
Notifications
You must be signed in to change notification settings - Fork 63
/
Copy pathsearch.js
31 lines (28 loc) · 958 Bytes
/
search.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
const form = document.querySelector("#form");
const input = document.querySelector("#input");
const names = document.querySelectorAll(".name .content")
const result = document.querySelector("#result");
let contentFound = [];
let found = false;
div = document.createElement('div');
div.textContent = "";
form.addEventListener('submit', async(event)=>{
found = false;
div.textContent = "";
result.textContent = "";
event.preventDefault();
names.forEach(element => {
const inputName = element.textContent.toUpperCase();
const searchName = input.value.toUpperCase();
if(inputName.includes(searchName)){
let ele = element.parentNode.parentNode.parentNode;
result.appendChild(ele.cloneNode(true));
found = true;
}
})
if(found == false){
div.textContent = "Not found";
result.appendChild(div);
div.classList.add('not-found');
}
})