The HTML , HEAD , and TITLE Elements


The <HTML> , <HEAD> , and <TITLE> Elements

As it turns out, the <HTML> , <HEAD> , and <TITLE> elements are all covered very well in the discussion about JavaScript's core HTML properties in Chapters 5, "Using Core HTML Properties," and 6, "Using Core HTML Methods and Events." (In JavaScript, these elements correspond to the html , head , and title objects.) Each of these elements has only one additional property not covered in those chapters (and no additional methods or events).

How do you get access to an element such as <HTML> in JavaScript? You do that just as you would get access to any element, such as giving this element an ID and then using methods like getElementById to get access to the element as an object in JavaScript. If you've given the <HTML> element the ID "html1" like this: <HTML ID="html1"> , for example, you can access it like this: document.getElementById("html1") , and access properties like this: document.getElementById("html1"). property , and methods like this: document.getElementById("html1"). method(...) . As with other any other element, you can treat the <HTML> element as an object and assign it to a variable like this: var html1 = document.getElementById("html1") . In this way, any element in a web page becomes an object for you to work with in JavaScript.

Besides the core HTML properties, the <HTML> element also includes a read/write version property in JavaScript, as of Netscape Navigator 6 and Internet Explorer 6. This property sets or gets the HTML version for the current document. In fact, although this property is new in both browsers, it's been deprecatedrendered obsoleteby W3C, which says you should indicate the HTML version with the <!DOCTYPE> element. (If used, this element is the very first in an HTML document, before even the <HTML> element.) Here, for example, are three <!DOCTYPE> elements, which specify HTML 4.01 strict (strict adherence to the HTML 4.01 recommendation), HTML 4.01 transitional (includes support for deprecated features), and HTML 4.01 frameset (which is the same as the strict version, but includes support for frames ):

 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN"          "http://www.w3.org/TR/REC-html40/strict.dtd">  <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"          "http://www.w3.org/TR/REC-html40/loose.dtd">  <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Frameset//EN"          "http://www.w3.org/TR/REC-html40/frameset.dtd"> 

The <HEAD> element also includes a read/write profile property as of Netscape Navigator 6 and Internet Explorer 6. This property sets or gets one or more Uniform Resource Identifiers (URIs) at which the document's properties and values for those properties are specified. If that sounds vague, it isno browser uses the PROFILE HTML attribute yet (which corresponds to the JavaScript profile property), and its true purpose has yet to be settled on.

The <TITLE> element also has a read/write text property, as of Netscape Navigator 6 and Internet Explorer 4.0, which holds the text of the document's title. As we'll see in this chapter, that text is traditionally accessed as document.title , but you also can access it with the text property of the <TITLE> element.

And that's itthat gives us the framework we need. Now we're ready to start working with the huge, and important, document object.



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