Solved. My code search inside a large html table, which contains email related fields, and add and remove elements to the menu based on what the user types in the input text field.
Javascript code:
$(function(){
$('#msgIndexUL').superfish();
$("#menuFilterTextField").keyup(function(){
$("#msgIndex li:not('#menuFilter')").empty();
var id;
var mailSubject;
$(".results tbody tr").filter(":contains('"+ $("#menuFilterTextField").val() +"')").each(function(){
id = $(this).attr('id');
mailSubject = $($(this).children(".mailSubject")).html();
$("#msgIndex").append("<li><a href='#"+id+"'>"+mailSubject+"</a></li>");
});
});
});
And the html:
<ul id="msgIndexUL" class="sf-menu">
<li class="current">
<a href="##">Indice dei messaggi</a>
<ul id="msgIndex">
<li id="menuFilter"><input type="text" id="menuFilterTextField"/></li>
</ul>
</li>
</ul>