Using the document object to explain objects.
- "document" is the object in the above example.
- "write" is the method of this object. (Think of it as the arm and legs of this object that allows it to do something-anything.
of them have both methods and properties. "Document" is just one of the many
the layout of a webpage-background color, text, images etc. Now, the word
write" is a method of the document object. Most objects have more than one
method and property (You'll see what property is very soon), and this is
true for the document object as well. Lets have a look at some of the others
that the document object possesses.
The column on the left are properties of the
object. They are static attributes of the object. Lets say you want to write
out the date and time of the last modification to your page onto the screen.
Here's what you would do:
Whenever you update your page and save it, this script will
display the date and time of this occurrence. Something you can add to the
end of your page right now! In this example, "
document.lastModified" is a
property of "
document" Its a static attribute of the current document. In
order to show this property, we used the non-static method to write this
information out. Notice that we used "+" to put together "This page was last
modified:" and example. The "+" sign is used to "combine" strings into
one-similar to math, in a sense.
Lets try playing around with another document method then. Looking at the above chart, lets use "referrer", which gives the URL of the page that you came from to get here. Lets see what this might be useful for:
<script> document.writeln("Please thank this site for adding a link to me!") document.write(document.referrer) </script>
Ok, maybe not so useful like this, but you get the point.