The first uses the standards compliant method, "getElementById()", where the value of the HTML id attribute is placed within the parenthesis to identify which element is being referred to.
<form id="blueForm">
<input type="text" name="myText" id="blueElm">
The JavaScript reference for the text field in the above form would be:
document.getElementById("blueElm")
As you can see, it is a much shorter reference than the dot path with its listing of every containing object. Most of these lessons don't use the getElementById() method. This is because there still exists all over the web, scripts which use the dot path (I'm a believer in learning by example), and you must use the dot path when working with custom made objects. However, many CSS identifiers are applied to HTML elements which do not fit into any object containment hierarchy (other than the document). In these cases, it is nesscessary - as you'll see when you reach the dynamic html section of this site. You will not be hurt or have to unlearn anything by using both techniques. |