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

后端 未结 16 1916
无人及你
无人及你 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:04

    No. two elements with the same id are not valid. IDs are unique, if you wish to do something like that, use a class. Don't forget that elements can have multiple classes by using a space as a delimeter:

提交回复
热议问题