Using Object Properties and Methods in JavaScriptJavaScript programming centers on objects, to a large extent. We've already seen the document object and seen that one way to use that object is to use methods such as writeln to indicate that you want to write to a Web page. To use a method, you use the object's name , followed by a dot ( . ) and then the method name, such as document.writeln . Here are a few examples of methods:
There are hundreds of such methods available in JavaScript, and they let you work with a browser as it's running. In addition to using methods to cause the browser to perform some action, you can read and change the settings in the JavaScript objects using properties. For example, the document.fgcolor property holds the color of text in the current Web page. By changing the document.fgcolor property, you can change the color of that text. Here are some examples of properties, including the objects they belong to:
Using object methods and properties, you have access to what's going on in a Web page, and you have complete programmatic control over the browser in many areas. We'll be putting methods and properties to work in this chapter and the next two chapters. We've taken a look at the idea of methods and properties, but there's one more concept to cover before getting the actual programming details: using events in JavaScript. That topic is coming up. |