??? getElementsByTagName(): Retrieves all elements of a specific tag name. The W3C
specification indicates that HTML processors generally assume uppercase elements.
In current browsers, both uppercase and lowercase tag names will work. However, in
XHTML, the tag name must be lowercase. Therefore, I recommend that you use
lowercase.
??? childNodes: A property that retrieves all nodes that are direct descendants of an
element.
CHAPTER 2 n HTML, CSS, AND JAVASCRIPT 28
73ed30358d714f26dd2d9c0159f8cfe0
To see some of these functions in action, you need a document to work on:
Welcome to my web site
We sell all the widgets you need.
Now let??™s play with the document a little bit:
var mainContent = document.getElementById("main");
mainContent.style.backgroundColor = '#FF0000';
var paragraphs = document.getElementsByTagName("p");
for(i=0;i
{
paragraphs[i].style.fontSize = '2em';
}
var elements = document.getElementsByTagName("body")[0].childNodes;
for(i=0;i{
if(elements[i].nodeType == 1 && elements[i].id) alert(elements[i].id);
}
First up, you grab the