Why can only forms be referenced by dot notation?

后端 未结 2 391
萌比男神i
萌比男神i 2021-01-13 18:19

It seems like a simple beginners question, but I\'m unable to find an answer anywhere.

Let\'s say I have this HTML:

&
2条回答
  •  醉酒成梦
    2021-01-13 18:34

    The syntax you've posted is for form, to be specific.. It will work only with forms..

    You will need to use following line to make it work for divs...

    document.getElementsByName("myDiv")[0].getElementsByTagName("span")[0].innerHTML = "bar";
    

    There are other ways to do this too...

提交回复
热议问题