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

后端 未结 16 2162
无人及你
无人及你 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 05:55

    first text for one
    second text for one
    var ids = document.getElementById('one');

    ids contain only first div element. So even if there are multiple elements with the same id, the document object will return only first match.

提交回复
热议问题