-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.js
37 lines (33 loc) · 1.28 KB
/
main.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
36
37
let products = document.querySelectorAll(".product")
let search = document.querySelector("input[type='text']")
let maxPrice = document.querySelector("#maxprice")
let minPrice = document.querySelector("#minprice")
let btn = document.querySelector("button[type='button']")
btn.addEventListener("click", function () {
products.forEach(function (i) {
i.classList.remove("d-none")
let name = i.childNodes[3].childNodes[1]
if (!(name.textContent.toLowerCase().includes(search.value.toLowerCase()))) {
i.classList.add("d-none")
}
if (search.value == "") {
i.classList.remove("d-none")
}
maxValue = parseInt(maxPrice.value)
if (maxValue == ""){maxValue = Infinity}
let maxNum = i.childNodes[3].childNodes[3]
let maxprice = maxNum.textContent.replace("$", "")
maxprice = parseInt(maxprice)
if (maxprice > maxValue) {
i.classList.add("d-none")
}
minValue = parseInt(minPrice.value)
if (minValue == ""){minValue = 0}
let minNum = i.childNodes[3].childNodes[3]
let minprice = minNum.textContent.replace("$", "")
minprice = parseInt(minprice)
if (minprice < minValue) {
i.classList.add("d-none")
}
})
})