-
Notifications
You must be signed in to change notification settings - Fork 124
/
Copy pathfilter_project.js
41 lines (29 loc) · 1.27 KB
/
filter_project.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
38
39
40
41
const card_grid = document.querySelector('.card-grid');
const input = document.querySelector('.input-container input');
const category_select = document.querySelector('.input-container select');
// store all the project card present initially
const project_card = document.querySelectorAll('.card');
input.addEventListener('input', () => {
// get the value selected from dropdown
let category = category_select.value;
// select the value from input
const search_value = input.value;
category = category.toLowerCase()
if(category == 'title') {
category='heading'
}
// display the projects whose category matches and that category contains the input value
displayRequiredProjects(category, search_value);
})
const displayRequiredProjects = (category, search_value) => {
let found_card = "";
project_card.forEach((p) => {
const tag = p.querySelector(`.card__content .card__${category}`);
if(tag.innerText.toLowerCase().includes(search_value.toLowerCase())) {
found_card += p.outerHTML;
}
})
// if no such cards are found then display the following message
if(!found_card.length) found_card='<h2 style="color: red";>Cannot find the project</h1>'
card_grid.innerHTML = found_card;
};