It seems like a simple beginners question, but I\'m unable to find an answer anywhere.
Let\'s say I have this HTML:
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...
As designed by W3C.
There's really nothing to argue about. You can access the an HTMLCollection of all the forms on the page through document.forms
, much like you can images with document.images
, applets with document.applets
, links with document.links
and anchors with document.anchors
.
http://www.w3.org/TR/DOM-Level-2-HTML/html.html#ID-1689064