Skip to content

Instantly share code, notes, and snippets.

@JuanRangel
Last active December 8, 2022 01:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save JuanRangel/68736879ad996a4bd8f1407c8944b23e to your computer and use it in GitHub Desktop.
Save JuanRangel/68736879ad996a4bd8f1407c8944b23e to your computer and use it in GitHub Desktop.
StudenSearch
function studentSearch() {
const searchBar = `
<label for="search" class="student-search">
<span>Search by name</span>
<input id="search" placeholder="Search by name...">
<button type="button"><img src="img/icn-search.svg" alt="Search icon"></button>
</label>
`;
studentSearchBar.insertAdjacentHTML('beforeend', searchBar);
const searchingStudents = document.querySelector('#search');
studentSearchBar.addEventListener('keyup', (e) => {
const query = searchingStudents.value.toLowerCase();
let results = studentData.filter(function (student) {
let fullName = `${student.name.first.toLowerCase()} ${student.name.last.toLowerCase()}`
return fullName.includes(query);
});
showPage(results, 1);
addPagination(results);
// if statement for showing "no results'
if (results.length === 0) {
studentList.insertAdjacentHTML('beforeend', `<h1>No Results</h1>`);
}
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment