My first jQuery plugin
Update: November 3rd, 2008
I have been working with jQuery for a little while now so thought that I would try my hand at a plugin its basic but I think thats a good thing!
jQuery.fn.FilterList = function (list)
{
var timeout;
var theList = list;
var $input = $(this)
Bind();
function Bind()
{
$input.bind("keyup", function () { FilterList( $input.val()); })
}
function FilterList(forText)
{
theList.each
(
function ()
{
if (forText.length == 0 || MatchItem(forText, this.innerHTML))
$(this).show("normal");
else
$(this).hide("normal");
}
);
}
function MatchItem(term, value)
{
return value.match(new RegExp("(?![^&amp;amp;amp;;]+;)(?!<[^<>]*)(" + term + ")(?![^<>]*>)(?![^&amp;amp;amp;;]+;)", "gi"), "<em>$1</em>");
}
}
