Disney web site - 189Chapter 14Document Object Model EssentialsChapter 15 details node
189Chapter 14Document Object Model EssentialsChapter 15 details node properties and methods that are inherited by all HTML elements. Most are implemented in both IE5+ and W3C DOM browsers. Also look to the reference mate- rial for the documentobject in Chapter 18 for other valuable W3C DOM methods. A de facto standard: innerHTMLMicrosoft was the first to implement the innerHTMLproperty of all element objects startingwith IE4. While the W3C DOM has not supported this property, scripters frequently find itmore convenient to modify content dynamically by way of a string containing HTML markup, rather than creating and assembling element and text nodes. As a result, most modern W3CDOM browsers, including Moz1 and Safari1, support the read/write innerHTMLproperty of allelement objects as a de facto standard. When you assign a string containing HTML markup to the innerHTMLof an existing element, the browser automatically inserts the newly rendered elements into the document node tree. You may also use innerHTMLwith unmarked text to perform the equivalent of the IE-onlyinnerTextproperty. Despite the apparent convenience of the innerHTMLproperty compared to the step-by-stepprocess of manipulating element and text node objects, browsers operate on nodes muchmore efficiently than on assembly of long strings. This is one case where less JavaScript codedoes not necessarily translate to greater efficiency. Static W3C DOM HTML objectsThe Moz1 DOM (but unfortunately not IE5+) adheres to the core JavaScript notion of prototypeinheritance with respect to the object model. When a page loads into Moz1, the browser createsHTML objects based on the prototypes of each object defined by the W3C DOM. For example, ifyou use The Evaluator Sr. (Chapter 13) to see what kind of object the myPparagraph object is(enter document.getElementById( myP )into the top text box and click the Evaluate button), it reports that the object is based on the HTMLParagraphElementobject of the DOM. Every instance of a pelement object in the page inherits its default properties and methods fromHTMLParagraphElement(which, in turn, inherits from HTMLElement, Element, and Nodeobjects all detailed in the JavaScript binding appendix of the W3C DOM specification). You can use scripting to add properties to the prototypes of some of these static objects. Todo so, you must use new features added to Moz1. Two new methods __defineGetter__() and __defineSetter__() enable you to assign functions to a custom property of anobject. These methods are Mozilla-specific. To prevent their possible collision with standardizedimplementations of these features in future implementations of ECMAScript, the underscorecharacters on either side of the method name are pairs of underscore characters. The functions execute whenever the property is read (the function assigned via the__defineGetter__()method) or modified (the function assigned via the __defineSetter__()method). The common way to define these functions is in the form of an anonymousfunction (see Chapter 33). The formats for the two statements that assign these behaviorsto an object prototype are as follows: object.prototype.__defineGetter__( propName , function([param1[,…[,paramN]]]) { // statementsreturn returnValue; }) Note