Hey gang, in this JavaScript DOM tutorial I’ll show you how we can create a custom JS search filter using the ‘keyup’ event as well as several other techniques we’ve learnt so far in the series.
—– COURSE LINKS:
+ Atom editor – https://atom.io/a
+ GitHub Repo – https://github.com/iamshaunjp/JavaScript-DOM-Tutorial
———————————————————————————————
Other tutorials:
—– JAVASCRIPT FOR BEGINNERS:
—– CSS FOR BEGINNERS:
—– NODE.JS TUTORIALS
—– SUBSCRIBE TO CHANNEL – https://www.youtube.com/channel/UCW5YeuERMmlnqo4oq8vwUpg?sub_confirmation=1
============== The Net Ninja =====================
For more front-end development tutorials & to black-belt your coding skills, head over to – https://www.youtube.com/channel/UCW5YeuERMmlnqo4oq8vwUpg or http://thenetninja.co.uk
================== Social Links ==================
Twitter – @TheNetNinja – https://twitter.com/thenetninjauk
Original source
26 responses to “JavaScript DOM Tutorial #16 – Custom Search Filter”
/*filter books
const searchBar = document.forms['search-books'].querySelector('input'); //<input> tag içeriğini searchBar a atadı
searchBar.addEventListener('keyup', function(e){
const term = e.target.value.toLowerCase();
const books = list.getElementsByTagName('li');
Array.from(books).forEach(function(book){
const title = book.firstElementChild.textContent;
if(title.toLowerCase().indexOf(term)!= 1){
book.style.display = 'block';
}
else {
book.style.display = 'none';
}
})
})
*/
On github if(title.toLowerCase().indexOf(term)!= 1) part was written as if(title.toLowerCase().indexOf(e.target.value)!= 1) and that code does't give us the correct result if we
use UPPERCASE in searchbar
where to use const and where var ????
Can I replace the <li> tag with the <div> tag?
Thanks net ninja for giving so much back to the community with your tutorials.
Thank you for the tutorial and in case anybody else wants the code:
// filter books
const searchBar = document.forms['search-books'].queryselector('input');
searchBar.addEventListener('keyup', function(e){
const term = e.target.value.toLowerCase();
const books = list.getElementsByTagName('li');
Array.from(books).forEach(function(book){
const title = book.firstElementChild.text.Content;
if (title.toLowerCase().indexOf(term) != -1) {
book.style.disply = 'block';
} else {
book.style.disply = 'none';
}
})
})
can i get the code
This is just so cool! Thank man!
You are incredible. Udemy is so not needed.
Amazing! You are a genius! Thank you !
mooooooooooooooooooooooooooooooooooarrr
please
I like this video, and I am trying to do the same but there was as error:
"Uncaught ReferenceError: list is not defined at HTMLInputElement.<anonymous>"
Is it possible to see your HTML file or can you give me the solution
Wow Man !! , Great tutorial Thank you …
I became you fan after watching these dom element videos in javascript thanks alot
you are great ninja
Thank you Net Ninja !
Wow, this is better than the majority of videos I buy on Udemy. With the explosion of JavaScript, and most employers wanting “Vanilla JS”, I’ve been searching for good, quality Vanilla JS videos. The topic/project here is amazing. Please post more project-based JavaScript videos like these! Your teaching style is amazing!
.includes() will be little bit more concisely and semantically correct than .indexOf()
Big thx for this tutor!
how come all the ‘li’ is being displayed back once you delete everything in the form field? wouldn’t that be an empty ‘term’ const and not be an index of any of the titles?
thanks ninja you are an excellent teacher.
Tutorial Series wa Subarashi deshta, arigato gozaimashita Net Ninja san!
I think it'll be better if you'll cache DOM elements. It's not god idea to search LI tags over and over again on 'keyup' event. (line 51)
Much better will be to make array from LI.textContent and loop through array
awesome!
will you do tutorials about back-end? oh that would be lovely 😀
Nice one
Awesome… thanks alot 👍
awesome, thank you so much.
anyway, is it possible to make the list have pagination by javascript only without server side language?
i was wondering if we could set the maximum list by 5 for the books to read lists, and then when user add the new book to the lists it will automatically listing to new div/section of page 2 but still in the same html. so it wouldnt make a very long list to scroll.
May God Bless you for your kindness share knowledge.
have good day
I loved been with u guys, you're the best.
pls can u make a series on online billing system.
You are god!!!