-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
36 lines (34 loc) · 1.06 KB
/
script.js
File metadata and controls
36 lines (34 loc) · 1.06 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
// get filter element
const filterElement = document.querySelector('input')
// get cards elements
const cards = document.querySelectorAll('.cards li')
// add input event for the filter element
filterElement.addEventListener('input', filterCards)
//Filter function
function filterCards() {
// if the filter is not empty
if(filterElement.value != ''){
// for each card of cards
for(let card of cards){
// get card heading (title)
let title = card.querySelector('h2')
// tranform to lower case
title = title.textContent.toLowerCase()
// transform filter text to lower case
let filterText = filterElement.value.toLowerCase()
// if card title does not include the filter text
if(!title.includes(filterText))
// hide the card element
card.classList.add('invisible')
else
// unhide the card element
card.classList.remove('invisible')
}
}else{
// for each card of cards
for(let card of cards){
// unhide the card element
card.classList.remove('invisible')
}
}
}