The :contains() jQuery selector allows you to match find elements that contain a specified string of text. What I want to do seems related: I'm providing the user a "filter" text box that they can type in, and I have a set of list items.
I want to have all list items that do not contain the text the user entered in the textbox be hidden as they type.
I can listen for the keyup event on the textbox, but I'm not sure how to do two things:
- "Invert" the :contains() selector results--I want to select elements that don't match, and hide them.
- Make the matching case sensitive.
It's occurred to me that I could use .filter( function(index) ), but I'm wondering if I'm overthinking this--is there a way to accomplish this already with the selectors/functions built-in to jQuery?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…