As mentioned before,
JavaScript is object oriented scripting language. Iits real power lies
in the way it accesses and manipulates the various elements on a web page.
It uses DOM (Document Object Model) API to interact with the contents
within the website. DOM is a platform and language independent interface
that allows programs and scripts to dynamically access and updates the
content, structure, and style of documents.
DOM objects are organized
in a tree like structure or parent child hierarchy. Because JavaScript
uses DOM, it stores components of a web document in a parent child hierarchy,
as shown in Figure 1.
Figure1
The window object
is the global object that has all properties and methods. All JavaScript
code is executed in this object. The Window object is accessed by typing
"window". All variables that you create on a web-page are the properties
of the window object and all the functions that you create become the
methods of the window object. The “documents” object is the child of ‘window’
object and allows you to access all the elements of a web page such as
images, buttons, and links on the web page.
To refer to an object,
you need to type the parent object name followed by its children object
name, separated by period(s). For example to address an image object in
a web document, you need to write window.document.image9.
Using DOM, JavaScript
can load a new page into the browser, open new windows, modify the text
of a webpage dynamically, and work with various parts of the browser window
or the web document.
|