09:49
0

 


Document Object

One of JavaScript's strengths is its ability to work with objects. In object-oriented programming and scripting languages, objects are a way to group or package together information and methods of working with this information in a convenient way. In order to access or change the attributes and contents of a Web page JavaScript provides a convenient object called the document object. According to Netscape it "contains information on the current document, and provides methods for displaying HTML output to the user." Here is a simple example broken down into four parts:
document.write("<P>Hello World</P>")
    
Document
An application object that contains information about the document loaded into a frame or window. In the JavaScript documentation the information about an object is referred to as its properties. Some of the properties of the document object can be changed others are read only.

The dot between the document object and the write()method is significant. The dot operator allows you to access information (object properties) and methods for working with that information in an object. The method or property of an object are on the right side of the dot and the object is on the left side. For example, information about the document that contains the script is available using the document object, the dot notation, and the names of properties of the document object:
  • document.bgColor - makes it possible to get or set the background color of the document
  • document.location - contains the URL for the current document
  • document.lastModified - holds the date when the document was last modified on server.
write()
write() is a method (also called a function) belonging to the document object. write() will output a string of text to the document. The round brackets following the word write are required. Any JavaScript expression can be placed inside the round brackets. The expression will be evaluated and the result converted, if necessary, to text to be written into the current Web page.

"<P>Hello World</P>"
The double quoted text is a "literal" string of text including HTML markup. In this case the literal text - the actual series of text characters - will be written into the current Web page.

0 comments:

Post a Comment

Adz