Skip to content Skip to sidebar Skip to footer

Jquery Class Selectors Like $(.someclass) Are Case Sensitive?

Given this HTML:
some text
Why does this JQuery selector match it on some browsers and some pages, but not on others? $('.OpenIdSele

Solution 1:

Turns out JQuery's class selector uses the new javascript method getElementsByClassName if the browser supports it. This method is case-insensitive on quirks-mode pages, and case-sensitive on non-quirksmode (aka standards-compliant) pages. Sure, it's usually obvious that the cases are different, but when the text is stuck in the middle of a long, complex selector it was hard to see. Apparently there are lots of case-sensitive differences between standards and quirks to watch out for.

Moral of the story: match case of everything in your HTML (element names, CSS classes, etc.) because you never know when a change to a browser or standard or library might invalidate your assumption about case-insensitivity.


Post a Comment for "Jquery Class Selectors Like $(.someclass) Are Case Sensitive?"