10.02.2014 Views

Beginning Ajax With ASP.NET (2006).pdf

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

JavaScript and the Document Object Model<br />

This gives the SuperAgent object all the characteristics of the Agent object. From this, you can further<br />

supplement this behavior by continuing to define properties and methods using the standard prototype<br />

syntax. To override any of the behavior of the Agent object, simply define properties and/or methods of<br />

the same name as the inherited objects.<br />

Summary of Material So Far<br />

Up to this point, this chapter has covered some of the basics, core concepts, and advanced object concepts<br />

of JavaScript. You have learned the basic syntax of JavaScript, how to define arrays, functions,<br />

event handlers, basic flow control, operators, and basic input/output operations, and performed a<br />

whirlwind tour of object-oriented concepts like constructors and the more advanced concepts like object<br />

inheritance via prototype chaining.<br />

One of JavaScript’s main goals is to allow dynamic manipulation of HTML documents, that is, to act as<br />

the scripting engine for DHTML (Dynamic HTML) web applications. Now that you have the core concepts<br />

of JavaScript and its operation covered, you can delve into the world of the Document Object<br />

Model and how to manipulate it.<br />

The Document Object Model<br />

The Document Object Model, or DOM, is an object that provides access to all the elements within the<br />

HTML document or page, such as links, forms fields, anchors, and so on. There are, however, several object<br />

models that relate to the DOM as it stands today that warrant some discussion. Earlier in this chapter, we<br />

briefly discussed the evolution of the DOM by various browser vendors and touched upon the various<br />

incompatibilities that have occurred as the object models have evolved over time. This is both a good and<br />

a bad thing. On one hand, it means that the object models are constantly being reviewed and improved<br />

upon, with the ultimate goal to reach a level of standardization, or commonality, among all the major<br />

browser vendors. This is one of the major tenets of the W3C, which was also mentioned at the beginning<br />

of this chapter. On the other hand, it means that, over time, vendors have implemented browser features<br />

in different ways, which makes it hard for developers to implement functionality without ensuring that it<br />

works in browsers from various vendors, as well as different versions of browsers from the same vendor.<br />

There are essentially three object models that form the primary pieces of the JavaScript object model set:<br />

❑<br />

❑<br />

❑<br />

The core JavaScript object library and language<br />

The Browser Object Model<br />

The Document Object Model<br />

So far in the chapter, we have covered the first piece of the JavaScript object model set, and this is fairly<br />

consistent across browser vendors and the various browser versions.<br />

The second piece represents the object model exhibited by the browser itself. This traditionally comprises<br />

a window object as the root object, which holds references to other objects contained within it such as the<br />

document object that contains the page elements. The document object is the reference to the standard<br />

DOM — the third of the primary pieces of the JavaScript object model set — and is the reference by which<br />

you can manipulate page elements dynamically using JavaScript. Figure 3-3 shows this relationship.<br />

51

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!