Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 358
Josh Johnson Avatar asked Apr 22 '11 13:04

Josh Johnson


People also ask

Are jQuery selectors case sensitive?

jQuery attribute value selectors are generally case-sensitive.

How use contains in jQuery?

jQuery :contains() SelectorThe :contains() selector selects elements containing the specified string. The string can be contained directly in the element as text, or in a child element. This is mostly used together with another selector to select the elements containing the text in a group (like in the example above).

Is CSS class case sensitive?

CSS is case insensitive. And CSS class, id , urls, font-families are case sensitive.


1 Answers

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/

like image 176
Nicky Waites Avatar answered Sep 20 '22 13:09

Nicky Waites