JQuery class selectors like $(.someClass) are case sensitive?

前端 未结 1 1838
爱一瞬间的悲伤
爱一瞬间的悲伤 2020-12-06 05:13

Given this HTML:

some text

Why does this JQuery selector match it on some browsers and some

1条回答
  •  -上瘾入骨i
    2020-12-06 05:38

    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.

    0 讨论(0)
提交回复
热议问题