In the DOM are node ids case sensititve?

前端 未结 5 2064
情书的邮戳
情书的邮戳 2020-12-03 02:47

Is this HTML valid? Or is the id \'a\' the same as the id \'A\'?

alpha
Alpha
5条回答
  •  我在风中等你
    2020-12-03 03:47

    Bit of clarification here since all the above answers are only partially correct. In the context of the DOM and Java Script yes, ID's are case sensitive. In CSS they are not, as CSS is entirely case insensitive.

    http://www.w3.org/TR/css3-selectors/#casesens

    All Selectors syntax is case-insensitive within the ASCII range (i.e. [a-z] and [A-Z] are equivalent), except for parts that are not under the control of Selectors. The case sensitivity of document language element names, attribute names, and attribute values in selectors depends on the document language. For example, in HTML, element names are case-insensitive, but in XML, they are case-sensitive. Case sensitivity of namespace prefixes is defined in [CSS3NAMESPACE].

    Because of this it is a bad idea to have two id's in different cases since you won't be able to style them independently by id.

提交回复
热议问题