全部博文(2759)
分类:
2012-05-13 12:36:10
原文地址:javascript(五)--Core DOM对象 作者:yourtommy
Property | Description | DOM |
---|---|---|
attributes | Returns a collection of a node's attributes | 1 |
baseURI | Returns the absolute base URI of a node | 3 |
childNodes | Returns a NodeList of child nodes for a node | 1 |
firstChild | Returns the first child of a node | 1 |
lastChild | Returns the last child of a node | 1 |
localName | Returns the local part of the name of a node | 2 |
namespaceURI | Returns the namespace URI of a node | 2 |
nextSibling | Returns the next node at the same node tree level | 1 |
nodeName | Returns the name of a node, depending on its type | 1 |
nodeType | Returns the type of a node | 1 |
nodeValue | Sets or returns the value of a node, depending on its type | 1 |
ownerDocument | Returns the root element (document object) for a node | 2 |
parentNode | Returns the parent node of a node | 1 |
prefix | Sets or returns the namespace prefix of a node | 2 |
previousSibling | Returns the previous node at the same node tree level | 1 |
textContent | Sets or returns the textual content of a node and its descendants | 3 |
Method | Description | DOM |
---|---|---|
appendChild() | Adds a new child node, to the specified node, as the last child node | 1 |
cloneNode() | Clones a node | 1 |
compareDocumentPosition() | Compares the document position of two nodes | 1 |
getFeature(feature,version) | Returns a DOM object which implements the specialized APIs of the specified feature and version | 3 |
getUserData(key) | Returns the object associated to a key on a this node. The object must first have been set to this node by calling setUserData with the same key | 3 |
hasAttributes() | Returns true if a node has any attributes, otherwise it returns false | 2 |
hasChildNodes() | Returns true if a node has any child nodes, otherwise it returns false | 1 |
insertBefore() | Inserts a new child node before a specified, existing, child node | 1 |
isDefaultNamespace() | Returns true if the specified namespaceURI is the default, otherwise false | 3 |
isEqualNode() | Checks if two nodes are equal | 3 |
isSameNode() | Checks if two nodes are the same node | 3 |
isSupported() | Returns true if a specified feature is supported on a node, otherwise false | 2 |
lookupNamespaceURI() | Returns the namespace URI matching a specified prefix | 3 |
lookupPrefix() | Returns the prefix matching a specified namespace URI | 3 |
normalize() | Joins adjacent text nodes and removes empty text nodes | 2 |
removeChild() | Removes a child node | 1 |
replaceChild() | Replaces a child node | 1 |
setUserData(key,data,handler) | Associates an object to a key on a node | 3 |
Node type | Description | Children | |
---|---|---|---|
1 | Element | Represents an element | Element, Text, Comment, ProcessingInstruction, CDATASection, EntityReference |
2 | Attr | Represents an attribute | Text, EntityReference |
3 | Text | Represents textual content in an element or attribute | None |
4 | CDATASection | Represents a CDATA section in a document (text that will NOT be parsed by a parser) | None |
5 | EntityReference | Represents an entity reference | Element, ProcessingInstruction, Comment, Text, CDATASection, EntityReference |
6 | Entity | Represents an entity | Element, ProcessingInstruction, Comment, Text, CDATASection, EntityReference |
7 | ProcessingInstruction | Represents a processing instruction | None |
8 | Comment | Represents a comment | None |
9 | Document | Represents the entire document (the root-node of the DOM tree) | Element, ProcessingInstruction, Comment, DocumentType |
10 | DocumentType | Provides an interface to the entities defined for the document | None |
11 | DocumentFragment | Represents a "lightweight" Document object, which can hold a portion of a document | Element, ProcessingInstruction, Comment, Text, CDATASection, EntityReference |
12 | Notation | Represents a notation declared in the DTD | None |
Node type | nodeName returns | nodeValue returns | |
---|---|---|---|
1 | Element | element name | null |
2 | Attr | attribute name | attribute value |
3 | Text | #text | content of node |
4 | CDATASection | #cdata-section | content of node |
5 | EntityReference | entity reference name | null |
6 | Entity | entity name | null |
7 | ProcessingInstruction | target | content of node |
8 | Comment | #comment | comment text |
9 | Document | #document | null |
10 | DocumentType | doctype name | null |
11 | DocumentFragment | #document fragment | null |
12 | Notation | notation name | null |
NodeType | Named Constant |
---|---|
1 | ELEMENT_NODE |
2 | ATTRIBUTE_NODE |
3 | TEXT_NODE |
4 | CDATA_SECTION_NODE |
5 | ENTITY_REFERENCE_NODE |
6 | ENTITY_NODE |
7 | PROCESSING_INSTRUCTION_NODE |
8 | COMMENT_NODE |
9 | DOCUMENT_NODE |
10 | DOCUMENT_TYPE_NODE |
11 | DOCUMENT_FRAGMENT_NODE |
12 | NOTATION_NODE |
The NodeList object represents an ordered collection of nodes.
The nodes in the NodeList can be accessed through their index number (starting from 0).
A NodeList object could be a Node's collection of child nodes.
Property | Description | DOM |
---|---|---|
length | Returns the number of nodes in the collection | 1 |
Method | Description | DOM |
---|---|---|
item() | Returns the node at the specified index in a node list | 1 |
The NamedNodeMap object represents an unordered collection of nodes.
The nodes in the NamedNodeMap can be accessed through their name.
A NamedNodeMap object could be a Node's collection of attributes.
Property | Description | DOM |
---|---|---|
length | Returns the number of nodes in the collection | 1 |
Method | Description | DOM |
---|---|---|
getNamedItem() | Returns the specified node (by name) | 1 |
getNamedItemNS() | Returns the specified node (by name and namespace) | 2 |
item() | Returns the node at the specified index in the namedNodeMap | 1 |
removeNamedItem() | Removes the specified node (by name) | 1 |
removeNamedItemNS() | Removes the specified node (by name and namespace) | 2 |
setNamedItem() | Sets the specified node (by name) | 1 |
setNamedItemNS() | Sets the specified node (by name and namespace) | 2 |
The Document object is the root of a document tree.
The Document object gives us access to the document's data.
Since element nodes, text nodes, attributes, comments, etc. cannot exist outside the document, the Document object contains methods to create these objects. All Node objects have a ownerDocument property which associates them with the Document where they were created.
Property | Description | DOM |
---|---|---|
doctype | Returns the Document Type Declaration associated with the document | 1 |
documentElement | Returns the Document Element of the document (the HTML element) | 1 |
documentURI | Sets or returns the location of the document | 3 |
domConfig | Returns the configuration used when normalizeDocument() is invoked | 3 |
implementation | Returns the DOMImplementation object that handles this document | 1 |
inputEncoding | Returns the encoding, character set, used for the document | 3 |
strictErrorChecking | Sets or returns whether error-checking is enforced or not | 3 |
xmlEncoding | Returns the XML encoding of the XML document | 3 |
xmlStandalone | Sets or returns whether the XML document is standalone or not | 3 |
xmlVersion | Sets or returns the XML version of the XML document | 3 |
Method | Description | DOM |
---|---|---|
adoptNode(node) | Adopts a node from another document to this document. Returns the adopted node | 3 |
createAttribute() | Creates an attribute node | 1 |
createAttributeNS(URI,name) | Creates an attribute with the specified name and namspaceURI | 2 |
createCDATASection() | Creates a CDATA node with the specified text. For XML DOM only | 1 |
createComment() | Creates a Comment node with the specified text | 1 |
createDocumentFragment() | Creates an empty DocumentFragment node | 1 |
createElement() | Creates an Element node | 1 |
createElementNS() | Creates an element with the specified namespace | 2 |
createEntityReference() | Creates an EntityReference node. For XML DOM only | 1 |
createProcessingInstruction() | Creates an EntityReference node. For XML DOM only | 1 |
createTextNode() | Creates a Text node | 1 |
getElementById() | Returns the element that has the ID attribute with the specified value | 2 |
getElementsByTagName() | Returns a NodeList containing all elements with the specified tagname | 1 |
getElementsByTagNameNS() | Returns a NodeList containing all elements with the specified namespaceURI and tagname | 2 |
importNode() | Imports a node from another document | 2 |
normalizeDocument() | Removes empty Text nodes, and joins adjacent nodes | 3 |
renameNode() | Renames the specified node | 3 |
The Element object represents an element in the HTML document.
The Element object can have child nodes of type Element, Text, Comment, CDATASection, ProcessingInstruction, and EntityReference.
The Element object can have attributes, which have the node type Attr.
Property | Description | DOM |
---|---|---|
schemaTypeInfo | Returns the type information of the element. | 3 |
tagName | Returns the tag name of the element | 1 |
Method | Description | DOM |
---|---|---|
getAttribute() | Returns the specified attribute value | 1 |
getAttributeNS() | Returns the specified attribute value, with the specified namespace. For XML DOM only | 2 |
getAttributeNode() | Returns the specified attribute node | 1 |
getAttributeNodeNS() | Returns the specified attribute node, with the specified namespace. For XML DOM only | 3 |
getElementsByTagName() | Returns a collection of all child elements with the specified tagname | 1 |
getElementsByTagNameNS() | Returns a collection of all child elements with the specified tagname and namespace. For XML DOM only | 2 |
hasAttribute() | Returns true if the element has the specified attribute, otherwise it returns false | 2 |
hasAttributeNS() | Returns true if the element has the specified attribute, with the specified namespace, otherwise it returns false. For XML DOM only | 2 |
removeAttribute() | Removes the specified attribute | 1 |
removeAttributeNS() | Removes the attribute with the specified name and namespace. For XML DOM only | 2 |
removeAttributeNode() | Removes the specified attribute node, and returns the removed node | 1 |
setAttribute() | Sets or changes the specified attribute, to the specified value | 1 |
setAttributeNS() | Sets or changes the specified attribute, with the specified namespace, to the specified value. For XML DOM only | 2 |
setAttributeNode() | Sets or changes the specified attribute node | 1 |
setAttributeNodeNS() | Sets or changes the specified attribute node | 2 |
setIdAttribute() | 3 | |
setIdAttributeNS() | 3 | |
setIdAttributeNode() | 3 |
Property | Description | DOM |
---|---|---|
isId | Returns true if the attribute is of type ID, otherwise it returns false | 3 |
name | Returns the name of the attribute | 1 |
ownerElement | Returns the element this attribute belongs to | 2 |
schemaTypeInfo | Returns the type information of the attribute | 3 |
specified | Returns true if the attribute has been specified, otherwise it returns false | 1 |
value | Sets or returns the value of the attribute | 1 |