I'm pretty new to jQuery and I have the following issue:
I have made a JS script that compares user input to a bunch of <h3> elements that represent movie titles.
userinput = userinput.toLowerCase();
var list = document.getElementsByTagName("h3"); //dit wordt de lijst met titels
var i = list.length,
html, flag = false,
matches = [];
while (i--)//here, we loop through the list of <h3>'s
{
var html = list[i].innerHTML.toLowerCase();
if (-1 < html.indexOf(userinput))
{
flag = true;
matches.push(list[i]);
list[i].className = "matched";
}
}
if (!flag)//no match
{if (-1 !== html.indexOf(userinput))
alert('No match found !');
}
else//match!
{
for (var i = 0; i < matches.length; i++)
{
$("#overzicht_list").children(":not('')").remove();
}
}
as you can see, I first declare some variables that I'm gonna use. Then, I loop through the list of <h3> elements and if one of the elements matches the user input I want to do the following.
All of the elements in my container overzicht_list BUT the matched <h3> element should be removed. I tried using the following jQuery for this:
$("#overzicht_list").children(":not('')").remove();
But I really cannot figure out how to refer to the matches[i] array within jQuery! I tried #matches[i] and stuff like that, but that does not seem to work. Can any of you help me?
Thanks!