Case-insensitive attribute-value selector with Jquery

I need to get the value of the content attribute of a certain meta tag.

var someContent = $("meta[name=someKindOfId]").attr("content");

is how I usually do it. For business reasons, someKindOfId may be somekindofid. It could be other combinations of cases as well. I don't know.

What is the best way to search for this meta tag? Adding an id or other identifier is out of the question.


Solution 1:

You could use the jquery filter function like so

var meta = $('meta[name]').filter(function() {
    return this.name.toLowerCase() == 'somekindofid';
});

Based upon CSS selector case insensitive for attributes

http://jsfiddle.net/nickywaites/mkBvC/

Solution 2:

Also, for case insensitive attribute *= selector:

$("meta[name*=someKindOfId]")

You can use:

$('meta').filter(function() {
       return (/somekindofid/i).test($(this).attr('name'));
}).attr("content")