Make .find case insensitive

I can currently use:

$results.find('a[href$=".doc"]')

to find anything ending in .doc for editing. However, this seems to be case sensitive, that is, if the document ends with .DOC or .Doc, it will not find them. Can this be made case insensitive?

+3
source share
2 answers

You need to create a function that is not case sensitive.

$results.find('a').filter(function(){return /\.doc$/i.test(this.href);});

You can also list all 8 cases in the selector, but it will not scale easily.

$results.find('a[href$=".doc"],a[href$=".doC"],a[href$=".dOc"],a[href$=".dOC"],a[href$=".Doc"],a[href$=".DoC"],a[href$=".DOc"],a[href$=".DOC"]')
+8
source

try this i'm not sure:

$results.find("a:regex(href, /\.doc$/i)")

but this will work for all tags, so you can use it with $ results somehow

$("a:regex(href, /\.doc$/i)")

http://api.jquery.com/category/selectors/

0

Source: https://habr.com/ru/post/1768607/


All Articles