getElementsByTagName does not seem to work

前端 未结 1 979
再見小時候
再見小時候 2021-01-28 16:16

Can someone please explain why my code is not working !!

When I get the element By Id it works perfectly fine. But the same method with getElementsByTagName() does not.

1条回答
  •  傲寒
    傲寒 (楼主)
    2021-01-28 16:51

    As you can clearly see document,getElementsByTagName returns an array of elements, not a single element.

    So you have to follow proper indexing otherwise it will throw an exception as in your case.

    0 讨论(0)
提交回复
热议问题