DOM Level 1
The level 1 DOM is the first cross-browser DOM standardized by the W3C. Its objects are stored under the document object of the level 0 DOM.
Basic Node Properties
Each object has certain common properties:
nodeName is the name of the node (not the ID). The name is the tag name for HTML tag nodes, #document for the document node, and #text for text nodes. nodeType is a number describing the node's type: 1 for HTML tags, 3 for text nodes, and 9 for the document. nodeValue is the text contained within a text node. innerHTML is the HTML contents of a container node. id is the value of the ID attribute for the node. classname is the value of the class attribute for the node.
Relationship Properties
The following properties describe an object's relationship with others in the hierarchy:
firstChild is the first child node for the current node. lastChild is the last child object for the current node. childNodes is an array of all the child nodes under a node. previousSibling is the sibling before the current node. nextSibling is the sibling after the current node. parentNode is the object that contains the current node.
Offset Properties
Although not part of the W3C DOM, both Netscape and Internet Explorer support the following properties that provide information about a node's position:
offsetLeft is the distance from the left side of the browser window or containing object to the left edge of the node object. offsetTop is the distance from the top of the browser window or containing object to the top of the node object. offsetHeight is the height of the node object. offsetWidth is the width of the node object.
Style Properties
The style child object under each DOM object includes its style sheet properties. These are based on attributes of a style attribute, <style> tag, or external style sheet. See Hour 12, "Working with Style Sheets," for details on these properties.
Node Methods
The following methods are available for all DOM nodes:
appendChild(node) adds a new child node to the node after all its existing children. insertBefore(node,oldnode) inserts a new node before the specified existing child node. replaceChild(node,oldnode) replaces the specified old child node with a new node. removeChild(node) removes an existing child node. hasChildNodes() returns a Boolean value of true if the node has one or more children, or false if it has none. cloneNode() returns a copy of the current node. getAttribute(attribute_name) gets the value of the attribute you specify and stores it in a variable. setAttribute(attribute_name, value) sets the value of an attribute. removeAttribute(attribute_name) removes the attribute you specify. hasAttributes() simply returns true if the node has attributes, and false if it has none.
Document Object Methods and Properties
The following are methods and properties of the document object:
document.getElementById(ID) returns the element with the specified ID attribute. document.getElementsByTagName(tag) returns an array of the elements with the specified tag name. You can use the asterisk (*) as a wildcard to return an array containing all of the nodes in the document. document.createElement(tag) creates a new element with the specified tag name. document.createTextNode(text) creates a new text node containing the specified text. document.documentElement is an object that represents the document itself, and can be used to find information about the document.
|
Main Menu
|