Chapter 5. Using Core HTML Properties


Chapter 5. Using Core HTML Properties

graphics/chic01.gif

In the coming chapters, we're going to see a great many HTML elements and browser objects. Each of these elements and objects has properties, methods, and events; and if we were to list them all for each item, we would need more space than there is in this book. However, a great many JavaScript properties, methods , and events are common to nearly all HTML elements and to many browser objects, so I'll collect them into this and the next chapter, calling them JavaScript's core HTML properties, methods, and events . This chapter covers JavaScript's core HTML properties, and the next chapter (Chapter 6, "Using Core HTML Methods and Events") covers JavaScript's core HTML methods and events.

So when you want to look up the properties, methods, and events of an object, such as the window object, or a text field, or a button, you turn to the chapter that covers the object you wantone of Chapters 715. Some of the properties, methods, and events you find in those chapters will be JavaScript core items, and those chapters will refer you back to Chapters 5 and 6 for those items.

Take a look at the Table 5.1, for example, which is a partial listing of the methods of the window object from Chapter 8, "Using window and frame Methods and Events" it's the beginning of Table 8.3. The attachEvent method is marked "See Chapter 6," indicating that this method is covered in Chapter 6. The attachEvent method is also a method of the document object, covered in Chapter 9, "Using the document and body Objects."

And it's a method of the HTML text elements in Chapter 11, "Working with HTML Text Elements," as well as a method of the HTML form objects covered in Chapters 12, "Working with Forms, Buttons, Check Boxes, and Radio Buttons," 13, "Working with Text and Select Controls," 14, "Working with Links, Lists, and Tables," and so on. As you can see, collecting JavaScript's HTML core properties, methods, and events here in Chapters 5 and 6 will save us an immense amount of duplication in later chapters (in fact, more duplication than would fit into the book).

Table 5.1. Partial List of the Methods of the window Object (from Table 8.3)

Method

NS2

NS3

NS4

NS6

IE3a

IE3b

IE4

IE5

IE5.5

IE6

alert

x

x

x

x

x

x

x

x

x

x

 

Returns: Nothing

 

Displays an alert box.

 

Syntax: window.alert([ msg ]) , where msg is a string holding the message to display in the alert box.

attachEvent

See Chapter 6.

back

   

x

x

           
 

Returns: Nothing

 

Navigates the Netscape Navigator back one page in the browser's history.

 

Not available in the Internet Explorer; so for cross-browser compatibility, it's probably best to stick with the history object (see Chapter 10, "Using the Navigator, Location, and History Objects").

                 

                 

                 

In this chapter, therefore, we're going to take a look at JavaScript's core HTML properties; these properties apply to nearly all HTML elements (such as <BODY> , <P> , <INPUT>, and so on) and to many browser objects (such as window , document , and so on) as well, as we'll see in the coming chapters. For example, the id property holds an object's ID value, as set in its ID attribute. The tagName property holds an element's tag name (such as "P" for a <P> element). The children property holds any child elements enclosed in an element, and so on.

Note that to cover all JavaScript's core HTML properties, methods, and events, we'll occasionally need to cover some topics that we haven't discussed yet and which are coming up in later chapters, such as style sheets or Dynamic HTML. That won't be a problem for the most part, but feel free to skip that material until you need it when dealing with the programming in later chapters.

So from where do JavaScript's core HTML properties that we're going to cover come? Although more have developed over the years , they originally came from HTML attributes.



Inside Javascript
Inside JavaScript
ISBN: 0735712859
EAN: 2147483647
Year: 2005
Pages: 492
Authors: Steve Holzner

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net