document.getElementById('searchInput').addEventListener('keyup', function(event) {
let searchQuery = event.target.value.toLowerCase(); console.log(searchQuery); })
1.1 document.getElementById(‘searchInput’)
grabs the html element (in this case it is the search bar input).
1.2 .addEventListener(‘keyup’, function() { })
An eventlistener is then appended to the end of the document – the eventlistener is “keyup”.
1.3 document.getElementById(‘searchInput’).addEventListener(‘keyup’, function(event) { let searchQuery = event.target.value.toLowerCase();
})
‘event’ is placed in the function parameter – within the function body a variable is assigned to event.target.value.toLowerCase(); this reads….
event.target gives you the element that triggered the event.
So, event.target.value retrieves the value of that element (an input field, in your example)…..
.toLowerCase then transforms what is entered into the search bar into lower case.
1.4 document.getElementById(‘searchInput’).addEventListener(‘keyup’, function(event) { let searchQuery = event.target.value.toLowerCase(); console.log(searchQuery); })
Finally searchQuery is logged to the console – which shows that whatever ever is typed into the search bar , whether in uppercase or lower, the console will log out that word in lower case.