Hello, colleagues
I am new in JavaScript, bumped into a problem and believe, you help and explain me
So here is my problem, I want to make a filter in js file would filter by names OR by IDs (id of name).
Now it filters just by names and not by IDs.
Could you, please, tell me how to solve my problem and explain what Ive done wrong?
“`
const search = document.getElementById(“search”);
const projectName = document.querySelectorAll(“.name”);
search.addEventListener(“keyup”, filterProjects);
function filterProjects(e) {
const text = e.target.value.toLowerCase();
projectName.forEach(function (project) {
const item = project.textContent;
if (item.toLowerCase().indexOf(text) != -1) {
project.parentElement.style.display = “”
} else {
project.parentElement.style.display = “none”
}
})
}
const filter = document.getElementById(“filter”);
const taskName = document.querySelectorAll(“.taskName”);
const taskID = document.fquerySelectorAll(“.taskID”);
search.addEventListener(“keyup”, filterProjects);
function filterProjects(e) {
const text = e.target.value.toLowerCase();
projectName.forEach(function (project) {
const item = project.textContent;
if (item.toLowerCase().indexOf(text) != -1) {
project.parentElement.style.display = “”
} else {
project.parentElement.style.display = “none”
}
})
}
function toggle(){
var blur = document.getElementById(‘blurbg’);
blur.classList.toggle(‘active’);
var popup = document.getElementById(‘newprojbox’);
popup.classList.toggle(‘active’);
var hide = document.getElementById(‘allprojects’)
hide.classList.toggle(‘passive’);
}
function tasktoggle(){
var taskblur = document.getElementById(‘blurbg’);
taskblur.classList.toggle(‘active’);
var taskpopup = document.getElementById(‘newtaskbox’);
taskpopup.classList.toggle(‘active’);
var taskhide = document.getElementById(‘alltasks’)
taskhide.classList.toggle(‘passive’);
}