• Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint
Share this Page URL
Help

Chapter 9. Using the document and body O... > The <HTML>, <HEAD>, and <TITLE> Elem...

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.


PREVIEW

                                                                          

Not a subscriber?

Start A Free Trial


  
  • Creative Edge
  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint