Case-insensitive attribute-value selector with Jquery

Josh Johnson picture Josh Johnson · Apr 22, 2011 · Viewed 18k times · Source

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.

Answer

Nicky Waites picture Nicky Waites · Apr 22, 2011

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/