It seems like a simple beginners question, but I’m unable to find an answer anywhere.
Let’s say I have this HTML:
<form name="myForm">
<input type="text" name="myTxt">
</form>
then I can use the following javascript
document.myForm.myTxt.value = 'foo';
But what if I have a div instead of a form?
<div name="myDiv">
<span name="mySpan"></span>
</div>
Why can’t I do the same thing here, like
document.myDiv.mySpan.innerHTML = "bar";
Seems like it should be possible to do, instead of having to use getELementById(), but I can’t make it work.
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 withdocument.images, applets withdocument.applets, links withdocument.linksand anchors withdocument.anchors.http://www.w3.org/TR/DOM-Level-2-HTML/html.html#ID-1689064