0

I grabbed the following snippet from the comments on this post at CSSTricks.com.

$.extend($.expr[":"], {
    "containsNC": function(elem, i, match, array) {
        return (elem.textContent || elem.innerText || "").toLowerCase().indexOf((match[3] || "").toLowerCase()) >= 0;
    }
});

Essentially, it provides a pseudo-selector :containsNC, which works just like :contains but is case-insensitive.

I want be able to detect if this selector is available so I can conditionally use :contains as a fallback.

How can I check for the presence of such a custom selector?

Alternatively, is there a better way to do the case insensitive matching in newer jQuery?

For reference, here's how I'm currently using :contains (to filter a list of Facebook friends)

$('#friend-search').on('keyup', 'input', function() {
    var $search = $(this).val(),
        $friends = $('.friend'),
        match = ':contains(' + $search + ')';
    $friends.hide().filter(match).show();
});
Sam Hanley
  • 4,707
  • 7
  • 35
  • 63
Zach Lysobey
  • 14,959
  • 20
  • 95
  • 149

1 Answers1

1

After posting this question, I did some poking around, and found the response quite easily:

var containsNC_isDefined = typeof $.expr[":"].containsNC === "function";
if (containsNC_isDefined) alert(":containsNC exists!"); 
Zach Lysobey
  • 14,959
  • 20
  • 95
  • 149