Christian web host - 79Chapter 14 .Document Object Model Essentials While recent

79Chapter 14 .Document Object Model Essentials While recent browsers continue to accept the omission of certain end tags (for TD, TR, and LI elements, for instance), it is best to get in the habit of supplying these end tags. If for no other reason, they help you visualize where an element s sphere of influence truly begins and ends. Any element that you intend to script whether to change its content or its style should have an identifier assigned to the element s IDattribute. Form control elements still require NAMEattributes if you submit the form content to a server. But you can freely assign a different identifier to a control s IDattribute. Scripts can use either the IDor the document.formReference.elementName reference to reach a control object. Identifiers are essentially the same as the values you assign to the NAME attributes of form and form input elements. Following the same rules for the NAMEattribute value, an ID identifier must be a single word (no white space), it cannot begin with a numeral (to avoid conflicts in JavaScript), and it should avoid punctuation symbols except for the underscore. While an element can be accessed by numeric index within the context of some surrounding element (such as the BODY), this is a risky practice when content is under construction. Unique identifiers make it much easier for scripts to reference objects and are not affected by changes in content order. New DOM concepts With the W3C DOM come several concepts that may be entirely new to you unless you have worked extensively with the terminology of tree hierarchies. Concepts that have the most impact on your scripting are new ways of referencing elements and nodes. Element referencing Script references to objects in the DOM Level 0 are observed in the W3C DOM for backward compatibility. Therefore, a form input element whose NAME attribute is assigned the value userName is addressed just like it always is: document.forms[0].userName or document.formName.userName But because all elements of a document are exposed to the document object, you can use the new document object method to access any element whose ID is assigned. The method is document.getElementById(), and the sole parameter is a string version of the identifier of the object whose reference you wish to get. To help put this in context with what you may have used with the IE4 object model, consider the following HTML paragraph tag:

In IE4+, you can reference this element with var elem = document.all.myParagraph IE4+ also enables you to omit the document.all. portion of the reference although for the sake of script readability (especially by others who want to study the script), I recommend that you use the document.all. prefix.
Searching for affordable and proven webhost to host and run your servlet applications? Go to Linux Web Hosting services and you will find it.

Leave a Reply