I'm using this javascript code, to filter search items but i want to filter a div element not just plain text.
var searchBox = document.querySelector("input");
var resultList = document.getElementById("resultList");
var resultsArray = [
"Walt Disney",
"Which color do you like?",
"Where are we?",
"Which wells are the best?",
"Who's on first?",
"Cowboys wear white",
"Wells are awesome!",
"Whoooppppeeeeee",
"Which Witch is Which",
"What's going on?",
"Well look at that!"
];
searchBox.addEventListener('keyup', function() {
var searchTerm = searchBox.value.toLowerCase();
// reset ul by removing all li items
while (resultList.hasChildNodes()) {
resultList.removeChild(resultList.lastChild);
}
// loop through array of sentences
for (var i = 0; i < resultsArray.length; i++) {
// if the array item starts with the search value AND the input box is not empty
if(resultsArray[i].toLowerCase().startsWith(searchTerm) && searchTerm != "") {
var li = document.createElement('li'); // create an li item
li.innerHTML = resultsArray[i]; // add the sentence to the new li item
resultList.append(li); // add new li item to resultList ul
}
}
// if resultList is empty after going through loop display 'no results found'
if (!resultList.hasChildNodes() && searchTerm != "") {
var li = document.createElement('li');
li.innerHTML = "no results found";
resultList.append(li);
}
});
i want to change var resultsArray items to div class items for example: "Walt Disney", to
<div class="item"><a href="walt-disney.html"><img src="images/walt-disney.png" alt="walt disney" border="0" /></a>walt disney</div>
walt-disney.htmlandimages/walt-disney.pngcome from?lielements have to do with your desired output?