Cycle through a list to see if there is a match for the characters entered into an input box 1

Cycle through a list to see if there is a match for the characters entered into an input box

const menu_items = document.querySelectorAll('li');

function getInputValue() {
    // Selecting the input element and get its value 
    var inputVal = document.getElementById("myInput").value;
    menu_items.forEach(item => {
        if (item.textContent.includes(inputVal)) {
            console.log(inputVal + " is in the list.")
        }
    })
}

Here is what the above code is Doing:
1. We’re selecting the input element and getting its value.
2. We’re selecting all the list items.
3. We’re looping through the list items and checking if the input value is in the list.

Similar Posts