Simple way to get element by id within a div tag?

后端 未结 8 573
忘了有多久
忘了有多久 2020-12-04 19:44

Please forgive me if I repeat the question.

I have HTML that all elements inside a div tag has different id, suppose I have already get the reference to the div, is

8条回答
  •  情深已故
    2020-12-04 20:27

    Unfortunately this is invalid HTML. An ID has to be unique in the whole HTML file.

    When you use Javascript's document.getElementById() it depends on the browser, which element it will return, mostly it's the first with a given ID.

    You will have no other chance as to re-assign your IDs, or alternatively using the class attribute.

提交回复
热议问题