Why can only forms be referenced by dot notation?

Viewed 1672

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.

2 Answers
Related