I am a self taught programmer and I am currently working on a job-listing website project. I have a job-listing page with a search function. Now, the user is able to search by job title and I would like to add the option to search by keywords.
HTML
Each job has 6 properties: job-title, job-location, job-type, job-industry and job-keyword. The job-keyword is a list since a job can have a different number of keywords.
<div class="job-listing">
<div class="container">
<div class="job-number">
<h2>We Found <span id="number-jobs-total" class="text-secondary">214</span> Offers For <span>You</span> </h2>
</div>
<ul class="job-board">
<li class="job job-1">
<div class="job-title">
<h2>Process Engineer</h2>
</div>
<div class="job-location">
<p>Location: Naypyitaw</p>
</div>
<div class="job-type">
<p>Type: Full-Time</p>
</div>
<div class="job-date">
<p>Published on 07/19/2019</p>
</div>
<div class="job-industry">
<p>Engineering</p>
</div>
<ul class="job-keywords">
<li>Engineering</li>
<li>Science</li>
</ul>
</li>
<li class="job job-2">
<div class="job-title">
<h2>Chief Financial Officier</h2>
</div>
<div class="job-location">
<p>Location: Naypyitaw</p>
</div>
<div class="job-type">
<p>Type: Full-Time</p>
</div>
<div class="job-date">
<p>Published on 07/18/2019</p>
</div>
</li>
<li class="job job-3">
<div class="job-title">
<h2>Assistant CEO</h2>
</div>
<div class="job-location">
<p>Location: Naypyitaw</p>
</div>
<div class="job-type">
<p>Type: Part-Time</p>
</div>
<div class="job-date">
<p>Published on 07/18/2019</p>
</div>
</li>
<li class="job job-4">
<div class="job-title">
<h2>Front-End Developer</h2>
</div>
<div class="job-location">
<p>Location: Naypyitaw</p>
</div>
<div class="job-type">
<p>Type: Part-Time</p>
</div>
<div class="job-date">
<p>Published on 07/18/2019</p>
</div>
</li>
</ul>
<nav class="pagination-container">
<ul class="pagination">
<li><a href="javascript:void(0)">Previous</a></li>
<li><a href="javascript:void(0)">Next</a></li>
</ul>
</nav>
</div>
</div>
JS for the search by title:
const search= document.querySelector(".skills");
const jobs = Array.from(document.querySelector(".job-board").children);
const filterJobs = term => {
jobs.filter(job =>{
const title = job.querySelector(".job-title").textContent.toLowerCase();
if(title.includes(term.toLowerCase()) || totalKeywords.includes(term.toLowerCase()) ){
job.style.display = "list-item";
} else{
job.style.display = "none";
}
});
};
search.addEventListener("keyup", e =>{
filterJobs(e.currentTarget.value.trim());
});
JS: What I have tried and I do not think I am very far but still not working
const search= document.querySelector(".skills");
const jobs = Array.from(document.querySelector(".job-board").children);
const filterJobs = term => {
jobs.filter(job =>{
const title = job.querySelector(".job-title").textContent.toLowerCase();
const keyword = job.querySelectorAll(".job-keywords li");
totalKeywords = [];
for(var i = 0 ; i < keyword.length ; i++){
totalKeywords.push(keyword[i].textContent);
}
console.log(totalKeywords);
if(title.includes(term.toLowerCase()) || totalKeywords.includes(term.toLowerCase()) ){
job.style.display = "list-item";
} else{
job.style.display = "none";
}
});
};
search.addEventListener("keyup", e =>{
filterJobs(e.currentTarget.value.trim());
});