behavior of javascript getElementById() when there are elements with duplicate IDs in HTML DOM?

后端 未结 5 1320
感动是毒
感动是毒 2020-12-04 01:42

Can someone shed some light on the behavior of javascript getElementById() when there are elements with duplicate IDs in HTML DOM??

5条回答
  •  情歌与酒
    2020-12-04 02:29

    If you have multiple elements with the same id, you can select them all with

    document.querySelectorAll("[id='myid']")
    

    However, if you are in control of it you should just fix the HTML.

提交回复
热议问题