I have a function that filters a listed based on the value of an input
field.  The .each() function looks at inside each anchor tag, and adds
a new class if there is a match.  But, I want the class to be added to
the parent, or prev element here, which is a holder div called
itemHolder.

For some reason it is not even adding the hidden class to the previous
element, which should be the itemHolder div.  Am I using this in the
wrong way?  Using .parent() does not work either.

    $("#filter").keyup(function() {
        var filter = $(this).val(),
        count = 0;
        $(".scroll a").each(function() {
            if ($(this).text().search(new RegExp(filter, "i")) < 0) {
                $(this).prev(".itemHolder").addClass("hidden");
            } else {
                $(this).prev(".itemHolder").removeClass("hidden");
                count++;
            }
        });
    });

Reply via email to