102 Part III . Document Objects Reference The getter function for the innerText property creates a range whose bound aries encompass the current object. Because a range includes only the text part of a document, the adjustment of the range boundaries to the current node encom passes all text, including text nodes of nested elements. Returning the string ver sion of the range provides a copy of all text inside the current element. For the setter action, the anonymous function defines one parameter variable, which is the text to replace the text inside an element. With the help, again, of the Range object, the range is cinched up to encompass the contents of the current node. Those contents are deleted, and new text node is created out of the value assigned to the property (in other words, passed as a parameter to the anonymous function). With the current object no longer containing any nodes after the dele tion, the appendChild() method inserts the new text node as a child to the current object. Setting the outerHTML property starts out the same as setting the innerText, but the new content which arrives as a string assigned to the parameter variable is converted into a fully formed set of nested nodes via the createContextualFragment() method. This method is invoked on any range object, but it does not affect the range to which it is attached. The value returned from the method is what s important, containing a node whose content is already set up as genuine DOM nodes. That s why the returned value can be passed to the replaceChild() method to replace the new content as HTML rather than plain text. But because the outerHTML property applies to the entire current element, it must use the roundabout way of replacing itself as a child of its parent. This pre vents the accidental modification of any siblings in the process. Where to Go from Here These past two chapters provided an overview of the core language and object model issues that anyone designing pages that use JavaScript must confront. The goal here is to stimulate your own thinking about how to embrace or discard levels of compatibility with your pages as you balance your desire to generate cool pages and serve your audience. From here on, the difficult choices are up to you. To help you choose the objects, properties, methods, and event handlers that best suit your requirements, the rest of the chapters in Part III and all of Part IV pro vide in-depth references to the document object model and core JavaScript lan guage features. Observe the compatibility ratings for each language term very carefully to help you determine which features best suit your audience s browsers. Most example listings are complete HTML pages that you can load in various browsers to see how they work. Many others invite you to explore how things work via The Evaluator (Chapter 13). Play around with the files, making modifications to build your own applications or expanding your working knowledge of JavaScript in the browser environment.
We recommend cheap and reliable webhost to host and run your web applications: Coldfusion Web Hosting services.