JavaScript Primers #8 A ???

By Joe Burns

http://www.htmlgoodies.com/primers/jsp/article.php/3478491/JavaScript-Primers-8-A-.htm (Back to article)

Use these to jump around or read it all


The Concept The Script The Script's Effect Deconstructing the Script
What You've Learned Your Assignment


The Concept

Whoa! Let's pause and review. We know that JavaScript has objects, which are like nouns or things. We know that objects have properties that describe how objects look, just as adjectives describe nouns. We refer to properties as object.property.

We also know that objects have methods, or actions that can be performed to the object. All methods have (parentheses) and are referred to as object.method(). Different objects have access to different properties and methods.

Now we'll learn the secret to understanding JavaScript, the hierarchy of Objects.

DON'T TELL A SOUL, but once you understand this, you've conquered JavaScript!


What We Mean


The Hierarchy of Objects Effect

All references begin with the top object, the Window (the browser screen), and go down. Windows and frames both belong to the Window object. You do not need to reference these unless there is more than one! Top, self, parent, and frames are built-in names for windows. Don't worry too much about these. Just know they exist.

Here are some examples. Notice they follow the hierarchy above, from top to bottom.

document.mypic.src = "pic1.gif"
"Window" is not needed at the very beginning. It is assumed that all this is inside of the window. This references an image named "mypic", changing its contents to "pic1.gif." Did you follow that? Document is the page the item is on, mypic is the item's name, and SRC is the item's source.
document.write(location.href)
write() is a method of the document object. Location.href displays the full URL of the window. Notice that Location and Document are at the same level (both are in green). That means that you get the location of that same-level document.


Deconstructing the Hierarchy of Objects


What You Have Learned


Your Assignment

Type in the full reference, starting with Window, even though it is not necessary. Note the picture name is mypic and the form name is myform.

  1. Reference the entire form:

  2. Reference the contents of lname:

  3. Reference the contents of fname:

  4. Change the picture to "marigold.gif":


The Concept The Script The Script's Effect Deconstructing the Script
What You've Learned Your Assignment

On To JavaScript Primer #9