HTML Tag Elements
All of the HTML tag elements have the following useful attributes:
-
element.id - the identifier for element.
-
element.className - the HTML class for element.
-
element.innerHTML - the HTML text inside element.
-
element.style - the style object for element.
The style object has an attributes corresponding to each of the CSS
attributes.
Setting one of these attributes immediately changes the visual
appearence of element.
The first two attributes are often specified directly in HTML as in the
following example:
<div id="theDiv" class="theClass">
…
</div>
Other attributes specified directly in HTML are also accessible as
element attributes in JavaScript.
Usually the attribute names are the same, but a few, such as
class
, are modified to avoid JavaScript keywords.
The HTML tag elements have no frequently used methods other than those
shared by all elements.
-
getElementsByTagName(tagName) - returns an array of HTML
elements whose tag name is tagName.
The entire descendent hierarchy is searched.
-
appendChild(element) - appends element at the
end of the childNodes array.
-
removeChild(child) - removes child from the
childNodes array.
-
replaceChild(newChild, oldChild) - replaces
oldChild in the childNodes array by newChild.