Can multiple different HTML elements have the same ID if they're different elements?

后端 未结 16 1917
无人及你
无人及你 2020-11-21 05:30

Can multiple HTML elements have the same ID if they\'re of different element types? Is a scenario like this valid? Eg:

div#foo
span#foo
a#foo
16条回答
  •  面向向阳花
    2020-11-21 06:08

    I think there is a difference between whether something SHOULD be unique or MUST be unique (i.e. enforced by web browsers).

    Should IDs be unique? YES.

    Must IDs be unique? NO, at least IE and FireFox allow multiple elements to have the same ID.

提交回复
热议问题