My html looks like this
<input id="txt" value=""></input>
<div class="link-item">jK</div>
<div class="link-item">JFOO</div>
my js
$('#txt').keyup(function(){
var txtsearch = $('#txt').val();
var filt = $("div.link-item:contains('" + txtsearch +"')");
$("div.link-item").css("display", "none")
.filter(filt)
.css("display", "block");
});
I'm looking to filter content dynamically on the client side. When I type a capital j, it only returns the second div whereas I want to get all div that contain j whether upper or lower case.
Here is my contribution, hope it helps :)
The :contains() selector is case sensitive.
Also created a demo if someone would like to try it out.
UPDATE
Sorry, must have misread your question.
Found this jQuery expression at http://bugs.jquery.com/ticket/278 to create a new selector that is case insensitive and I updated my demo.
You can change the
.contains
filter to be case insensitive or create your own selector.This creates a new selector: icontains (or you could name it insensitive-contains, or whatever suits your fancy). It's usage would be the same as contains:
$('div:icontains("Stack")');
would match:Or override the existing
.contains
filter:With this in place,
would select all three of these elements:
Why not use the
filter
function, and pass in a function that uses a case insensitive regex?DEMO
I don't believe there is a way to do this with a raw selector. The
contains
selector is case sensitive and there doesn't appear to be a case insensitive version. I think the best approach is to use a filter that manually queries the object