Package | dom.core |
Class | public class Node |
Inheritance | Node Object |
Implements | EventTarget |
Subclasses | Attr, CharacterData, Document, DocumentFragment, DocumentType, Element, Entity, EntityReference, Notation, ProcessingInstruction, XPathNamespace |
Introduced in: | DOM 1 Core |
Modified in: | DOM 3 Core |
See also
Property | Defined By | ||
---|---|---|---|
DOM 1 Core attributes : NamedNodeMap [read-only]
Returns an unordered collection of Attr nodes. | Node | ||
Non-Standard baseName : DOMString [read-only]
Returns the base name for the name qualified with the namespace. | Node | ||
DOM 3 Core baseURI : DOMString [read-only]
The absolute base URI of this node or null if the implementation
wasn't able to obtain an absolute URI. | Node | ||
DOM 1 Core childNodes : NodeList [read-only]
Returns an ordered collection of node objects that are children of
the current element. | Node | ||
Non-Standard dataType : *
Specifies the data type for this node. | Node | ||
Non-Standard definition : Node [read-only]
Returns the definition of the node in the document type definition (DTD) or schema. | Node | ||
DOM 1 Core firstChild : Node [read-only]
Returns the node's first child in the tree, or null if the node is
childless. | Node | ||
DOM 1 Core lastChild : Node [read-only]
Returns the last child of a node. | Node | ||
DOM 2 Core localName : DOMString [read-only]
Returns the local part of the qualified name of this node. | Node | ||
DOM 2 Core namespaceURI : DOMString [read-only]
The namespace URI of the node, or null if it is unspecified (read-only). | Node | ||
DOM 1 Core nextSibling : Node [read-only]
Returns the node immediately following the specified one in its
parent's childNodes list, or null if the specified node is the
last node in that list. | Node | ||
DOM 1 Core nodeName : DOMString [read-only]
Returns the name of the current node as a string. | Node | ||
Non-Standard nodePrincipal : nsIPrincipal [read-only]
Returns the nsIPrincipal object representing current security
context of the node. | Node | ||
DOM 1 Core nodeType : Number [read-only]
Returns an integer code representing the type of the node. | Node | ||
Non-Standard nodeTypedValue : *
Contains the node value expressed in its defined data type. | Node | ||
Non-Standard nodeTypeString : DOMString [read-only]
Returns the node type in string form. | Node | ||
DOM 1 Core nodeValue : DOMString
Returns or sets the value of the current node. | Node | ||
DOM 1 Core ownerDocument : Document [read-only]
The Document object associated with this node. | Node | ||
DOM 1 Core parentNode : Node [read-only]
Returns the parent of the specified node in the DOM tree. | Node | ||
Non-Standard parsed : Boolean [read-only]
Indicates the parsed status of the node and child nodes. | Node | ||
DOM 2 Core prefix : DOMString
Returns the namespace prefix of the specified node, or null if no
prefix is specified. | Node | ||
DOM 1 Core previousSibling : Node [read-only]
Returns the node immediately preceding the specified one in its
parent's childNodes list, null if the specified node is the first
in that list. | Node | ||
Non-Standard specified : Boolean [read-only]
Indicates whether the node (usually an attribute) is explicitly specified or derived
from a default value in the document type definition (DTD) or schema. | Node | ||
Non-Standard text : DOMString
Represents the text content of the node or the concatenated text representing the node and its descendants. | Node | ||
DOM 3 Core textContent : DOMString
Gets or sets the text content of a node and its descendants. | Node | ||
Non-Standard xml : DOMString [read-only]
Contains the XML representation of the node and all its descendants. | Node |
Method | Defined By | ||
---|---|---|---|
Associates a function with a particular event and binds the event to the current node. | Node | ||
DOM 3 Events addEventListenerNS(namespaceURI:DOMString, type:DOMString, listener:EventListener, useCapture:Boolean):void
Registers an event listener, depending on the useCapture parameter, on the
capture phase of the DOM event flow or its target and bubbling phases. | Node | ||
Adds a node to the end of the list of children of a specified parent node. | Node | ||
Returns a duplicate of the current node. | Node | ||
Compares the position of the current node against another node in any other document. | Node | ||
Dispatches an event to fire on a node artificially. | Node | ||
This method returns a specialized object which implements the
specialized APIs of the specified feature and version, as specified
in DOM Features. | Node | ||
Retrieves the object associated to a key on a this node. | Node | ||
DOM 2 Core hasAttributes():Boolean
Returns a boolean value of true or false, indicating if the current element
has any attributes or not. | Node | ||
DOM 1 Core hasChildNodes():Boolean
Returns a value that indicates whether the object has children. | Node | ||
Inserts the specified node before a reference element as a child of
the current node. | Node | ||
Returns true if the namespace is the default namespace on the given
node or false if not. | Node | ||
Tests whether two nodes are equal. | Node | ||
Returns whether this node is the same node as the given one. | Node | ||
Tests whether the DOM implementation implements a specific feature
and that feature is supported by this node. | Node | ||
Takes a prefix and returns the namespaceURI associated with it on the
given node if found (and null if not). | Node | ||
Returns the prefix for a given namespaceURI if present, and null if not. | Node | ||
DOM 1 Core normalize():void
Puts the specified node and all of its subtree into a "normalized"
form. | Node | ||
Removes a child node from the object. | Node | ||
Removes an event listener. | Node | ||
DOM 3 Events removeEventListenerNS(namespaceURI:DOMString, type:DOMString, listener:EventListener, useCapture:Boolean):void
Removes an event listener. | Node | ||
Replaces an existing child element with a new child element. | Node | ||
Applies the specified pattern-matching operation to this node's context and returns the list of matching nodes as IXMLDOMNodeList. | Node | ||
Applies the specified pattern-matching operation to this node's context and returns the first matching node. | Node | ||
Associate an object to a key on this node. | Node | ||
Processes this node and its children using the supplied Extensible Stylesheet Language Transformations
(XSLT) style sheet and returns the resulting transformation. | Node | ||
Processes this node and its children using the supplied Extensible Stylesheet Language Transformations (XSLT) style sheet
and returns the resulting transformation. | Node |
Constant | Defined By | ||
---|---|---|---|
DOM 1 Core ATTRIBUTE_NODE : Number = 2 [static]
The node is an Attr. | Node | ||
DOM 1 Core CDATA_SECTION_NODE : Number = 4 [static]
The node is a CDATASection. | Node | ||
DOM 1 Core COMMENT_NODE : Number = 8 [static]
The node is a Comment. | Node | ||
DOM 1 Core DOCUMENT_FRAGMENT_NODE : Number = 11 [static]
The node is a DocumentFragment. | Node | ||
DOM 1 Core DOCUMENT_NODE : Number = 9 [static]
The node is a Document. | Node | ||
DOM 3 Core DOCUMENT_POSITION_CONTAINED_BY : Number = 16 [static]
The node is contained by the reference node. | Node | ||
DOM 3 Core DOCUMENT_POSITION_CONTAINS : Number = 8 [static]
The node contains the reference node. | Node | ||
DOM 3 Core DOCUMENT_POSITION_DISCONNECTED : Number = 1 [static]
The two nodes are disconnected. | Node | ||
DOM 3 Core DOCUMENT_POSITION_FOLLOWING : Number = 4 [static]
The node follows the reference node. | Node | ||
DOM 3 Core DOCUMENT_POSITION_IMPLEMENTATION_SPECIFIC : Number = 32 [static]
The determination of preceding versus following is implementation-specific. | Node | ||
DOM 3 Core DOCUMENT_POSITION_PRECEDING : Number = 2 [static]
The second node precedes the reference node. | Node | ||
DOM 1 Core DOCUMENT_TYPE_NODE : Number = 10 [static]
The node is a DocumentType. | Node | ||
DOM 1 Core ELEMENT_NODE : Number = 1 [static]
The node is an Element. | Node | ||
DOM 1 Core ENTITY_NODE : Number = 6 [static]
The node is an Entity. | Node | ||
DOM 1 Core ENTITY_REFERENCE_NODE : Number = 5 [static]
The node is an EntityReference. | Node | ||
DOM 1 Core NOTATION_NODE : Number = 12 [static]
The node is a Notation. | Node | ||
DOM 1 Core PROCESSING_INSTRUCTION_NODE : Number = 7 [static]
The node is a ProcessingInstruction. | Node | ||
DOM 1 Core TEXT_NODE : Number = 3 [static]
The node is a Text node. | Node |
DOM 1 Core attributes | property |
attributes:NamedNodeMap
[read-only] Introduced in: | DOM 1 Core |
Returns an unordered collection of Attr nodes. If the element has no specified attributes, then the returned object has a length of 0 (zero).
Note: Trying to modify an Attribute Node that originated from an inline event assignment (e.g. onclick=) is something developers should avoid. If you want to use it, be aware that assigning values through the element.attributeName syntax will assign the JavaScript value for the element. When read through the same syntax, it will return the latest JavaScript value for the element attribute, or if it hasn't been assigned yet, the function generated by parsing the element's inline event assignment.
Note: Style isn't a "true" HTML attribute node, but a CCSStyleDeclaration. You can however use the above .attributes syntaxes and DOM functions to control its value, as well as the element.style.cssText syntax that returns all CSS attributes, or element.style.CSSattributeName (eg element.style.position) to control a single CSS attribute. In FireFox, all the above correctly update the CCSStyleDeclaration object, the element's attribute nodes and the .attributes collection. Consider quirksmode for compatibility issues in other browsers (see link below)
public function get attributes():NamedNodeMap
See also
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> <html> <head> <title>Attributes example</title> <script type="text/javascript"> function showFirstAttr() { var firstPara = document.getElementById("p1"); var outputText = document.getElementById("result"); // First, let's verify that the paragraph has some attributes if (firstPara.hasAttributes()) { var attrs = firstPara.attributes; var text = ""; for(var i=attrs.length-1; i>=0; i--) { text += attrs[i].name + "->" + attrs[i].value; } outputText.value = text; } else { outputText.value = "No attributes to show" }; } </script> </head> <body> <p id="p1" style="color: green;">Sample Paragraph</p> <form action=""> <p><input type="button" value="Show first attribute name and value" onclick="showFirstAttr();"> <input id="result" type="text" value=""></p> </form> </body> </html>
baseName | property |
baseName:DOMString
[read-only] Non-standard (Microsoft)
Returns the base name for the name qualified with the namespace.
It returns the right-hand side of a namespace qualified name. For example, it returns yyy for the element <xxx:yyy>. It always returns a non-empty string.
public function get baseName():DOMString
See also
DOM 3 Core baseURI | property |
baseURI:DOMString
[read-only] Introduced in: | DOM 3 Core |
The absolute base URI of this node or null if the implementation wasn't able to obtain an absolute URI. This value is computed as described in Base URIs. However, when the Document supports the feature "HTML" [DOM Level 2 HTML], the base URI is computed using first the value of the href attribute of the HTML BASE element if any, and the value of the documentURI attribute from the Document interface otherwise.
public function get baseURI():DOMString
See also
DOM 1 Core childNodes | property |
childNodes:NodeList
[read-only] Introduced in: | DOM 1 Core |
Returns an ordered collection of node objects that are children of the current element. If the element has no children, then the returned NodeList contains no node.
Note: The items in the collection of nodes are objects and not strings. To get data from those node objects, you must use their properties (e.g. elementNodeReference.childNodes[1].nodeName to get the name, etc.).
Note: The document object itself has 2 children: the Doctype declaration and the root element, typically referred to as documentElement. (In (X)HTML documents this is the HTML element.)
public function get childNodes():NodeList
See also
// parg is an object reference to a <p> element if (parg.hasChildNodes()) { // So, first we check if the object is not empty, if the object has child nodes var children = parg.childNodes; for (var i = 0; i < children.length; i++) { // do something with each child as children[i] // NOTE: List is live, Adding or removing children will change the list }; };
// This is one way to remove all children from a node // box is an object refrence to an element with children while (box.firstChild) { //The list is LIVE so it will re-index each call box.removeChild(box.firstChild); };
dataType | property |
dataType:*
Non-standard (Microsoft)
Specifies the data type for this node.
Value | Description |
---|---|
NODE_ATTRIBUTE | Contains the string representation of the data type specifier included in the schema, or Null if no data type is specified. |
NODE_CDATA_SECTION, NODE_COMMENT, NODE_DOCUMENT, NODE_DOCUMENT_FRAGMENT, NODE_DOCUMENT_TYPE, NODE_ENTITY, NODE_NOTATION, NODE_PROCESSING_INSTRUCTION, NODE_TEXT | Contains the constant string value "string." These node types do not have data types, so the dataType property cannot be set for these node types. Attempts to set this property are ignored. |
NODE_ELEMENT | Contains the string representation of the data type specifier included on the instance of the element or in the schema, or Null if no data type is specified. |
NODE_ENTITY_REFERENCE | Contains the string representation of the data type specifier for the referenced entity. This is limited to entities with a single data type on the root level element of the subtree corresponding to the entity. Contains Null if no data type is specified. It is not possible to set the data type of an entity reference. The data type must be set directly on the referenced element. Attempts to set the value of the dataType property are ignored. |
public function get dataType():*
public function set dataType(value:any):void
See also
definition | property |
definition:Node
[read-only] Non-standard (Microsoft)
Returns the definition of the node in the document type definition (DTD) or schema.
Value | Description |
---|---|
NODE_ENTITY_REFERENCE | Returns the node for the entity referenced; that is, the ENTITY element that was defined for a given ENTITYREF. Given the ENTITYREF &x;, for example, the definition property returns the node in the DOCTYPE node's entity collection that defines the corresponding ENTITY: <!ENTITY x "y">. |
NODE_ENTITY | For unparsed entities, returns the NOTATION definition from the DOCTYPE node's notation collection. For example, given the ENTITY <!ENTITY networth SYSTEM "networth.xls" NDATA XLS>, the definition property returns the node corresponding to the notation <!NOTATION XLS PUBLIC "http://example.microsoft.com/office/excel">. For parsed entities, returns Null. |
NODE_ATTRIBUTE | Returns the XML-Data Schema AttributeType for a given ATTRIBUTE node. For example, the definition property for the attribute myAttribute="123" returns the node corresponding to the element <AttributeType name= "myAttribute"> in the schema. Returns Null when a DTD is used or when no schema is present. |
NODE_ELEMENT | Returns the XML-Data Schema ElementType for a given ELEMENT node. For example, given the element <myelement>, the definition property returns the node <ElementType name="myelement"> in the specified external schema. Returns Null when a DTD is used or when no schema is present. |
NODE_CDATA_SECTION, NODE_COMMENT, NODE_DOCUMENT, NODE_DOCUMENT_FRAGMENT, NODE_DOCUMENT_TYPE, NODE_NOTATION, NODE_PROCESSING_INSTRUCTION, NODE_TEXT | Returns Null. |
public function get definition():Node
See also
DOM 1 Core firstChild | property |
firstChild:Node
[read-only] Introduced in: | DOM 1 Core |
Returns the node's first child in the tree, or null if the node is childless. If the node is a Document, it returns the first node in the list of its direct children.
Note: When applied to a document node, the returned node is not necessarily the root element of the document; it can also be a processing instruction, for example. If you need the root element, use document.documentElement.
public function get firstChild():Node
See also
<p id="para-01"> <span>First span</span> </p> <script type="text/javascript"> var p01 = document.getElementById('para-01'); alert(p01.firstChild.nodeName); </script>
In the above, the alert will show '#text' because a text node is inserted to maintain the whitespace between the end of the opening <p> and <span> tags. Any whitespace will cause the #text node to be inserted, from a single space to any number of spaces, returns, tabs, and so on.
Another #text node is inserted between the closing </span> and </p> tags.
If this whitespace is removed from the source, the #text nodes are not inserted and the span element becomes the paragraph's first child.
<p id="para-01"><span>First span</span></p> <script type="text/javascript"> var p01 = document.getElementById('para-01'); alert(p01.firstChild.nodeName) </script>
Now the alert will show 'SPAN'.
DOM 1 Core lastChild | property |
lastChild:Node
[read-only] Introduced in: | DOM 1 Core |
Returns the last child of a node. Returns null if there are no child elements.
public function get lastChild():Node
See also
var tr = document.getElementById("row1"); corner_td = tr.lastChild;
DOM 2 Core localName | property |
localName:DOMString
[read-only] Introduced in: | DOM 2 Core |
Returns the local part of the qualified name of this node.
Note: The local name of a node is that part of the node's qualified name that comes after the colon. Qualified names are typically used in XML as part of the namespace(s) of the particular XML documents. For example, in the qualified name ecomm:partners, partners is the local name and ecomm is the prefix:
<ecomm:business id="soda_shop" type="brick_n_mortar"> <ecomm:partners> <ecomm:partner id="1001">Tony's Syrup Warehouse</ecomm:partner> </ecomm:partners> </ecomm:business>
For nodes of any type other than ELEMENT_NODE and ATTRIBUTE_NODE and nodes created with a DOM Level 1 method, such as document.createElement, localName is always null.
public function get localName():DOMString
See also
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:svg="http://www.w3.org/2000/svg"> <head> <script type="application/javascript"><![CDATA[ function test() { var text = document.getElementById('text'); var circle = document.getElementById('circle'); text.value = "<svg:circle> has:\n" + "localName = '" + circle.localName + "'\n" + "namespaceURI = '" + circle.namespaceURI + "'"; } ]]></script> </head> <body onload="test()"> <svg:svg version="1.1" width="100px" height="100px" viewBox="0 0 100 100"> <svg:circle cx="50" cy="50" r="30" style="fill:#aaa" id="circle"/> </svg:svg> <textarea id="text" rows="4" cols="55"/> </body> </html>
DOM 2 Core namespaceURI | property |
namespaceURI:DOMString
[read-only] Introduced in: | DOM 2 Core |
The namespace URI of the node, or null if it is unspecified (read-only). When the node is a document, it returns the XML namespace for the current document.
Note: This is not a computed value that is the result of a namespace lookup based on an examination of the namespace declarations in scope. It is merely the namespace URI given at creation time.
Note: For nodes of any nodeType other than ELEMENT_NODE and ATTRIBUTE_NODE, and nodes created with a DOM Level 1 method, such as document.createElement, the value of namespaceURI is always null.
Note: You can create an element with the specified namespaceURI using the DOM Level 2 method document.createElementNS.
Note: Per the Namespaces in XML specification, an attribute does not inherit its namespace from the element it is attached to. If an attribute is not explicitly given a namespace, it has no namespace.
Note: The DOM does not handle or enforce namespace validation per se. It is up to the DOM application to do any validation necessary. Note too that the namespace prefix, once it is associated with a particular node, cannot be changed.
public function get namespaceURI():DOMString
See also
<browser/>
.
if (node.localName == "browser" && node.namespaceURI == "http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul") { // this is a XUL browser }
DOM 1 Core nextSibling | property |
nextSibling:Node
[read-only] Introduced in: | DOM 1 Core |
Returns the node immediately following the specified one in its parent's childNodes list, or null if the specified node is the last node in that list.
Note (Mozilla): Gecko-based browsers insert text nodes into a document to represent whitespace in the source markup. Therefore a node obtained for example via firstChild or previousSibling may refer to a whitespace text node, rather than the actual element the author intended to get.
public function get nextSibling():Node
See also
<div id="div-01">Here is div-01</div> <div id="div-02">Here is div-02</div> <script type="text/javascript"> var el = document.getElementById('div-01').nextSibling; document.write('<p>Siblings of div-01</p><ol>'); while (el) { document.write('<li>' + el.nodeName + '</li>'); el = el.nextSibling; } document.write('</ol>'); </script>
/************************************************** The following is written to the page as it loads: Siblings of div-01 1. #text 2. DIV 3. #text 4. SCRIPT 5. P 6. OL **************************************************/
The possible inclusion of text nodes in the DOM must be allowed for when traversing the DOM using nextSibling. See the resources in the Notes section.
DOM 1 Core nodeName | property |
nodeName:DOMString
[read-only] Introduced in: | DOM 1 Core |
Returns the name of the current node as a string.
Note: Here are the returned values for different types of nodes:
Interface | nodeName |
---|---|
Attr | same as Attr.name |
CDATASection | "#cdata-section" |
Comment | "#comment" |
Document | "#document" |
DocumentFragment | "#document-fragment" |
DocumentType | same as DocumentType.name |
Element | same as Element.tagName |
Entity | entity name |
EntityReference | name of entity reference |
Notation | notation name |
ProcessingInstruction | same as ProcessingInstruction.target |
text | "#text" |
public function get nodeName():DOMString
See also
<div id="d1">hello world</div> <input type="text" id="t"/>
and the following script:
var div1 = document.getElementById("d1"); var text_field = document.getElementById("t"); text_field.value = div1.nodeName;
In XHTML (or any other XML format), text_field's value would read "div". However, in HTML, text_field's value would read "DIV".
Note that tagName property could have been used instead, since nodeName has the same value as tagName for an element. Bear in mind, however, that nodeName will return #text for text nodes while tagName will return undefined.
nodePrincipal | property |
nodePrincipal:nsIPrincipal
[read-only] Non-standard (Mozilla)
Returns the nsIPrincipal object representing current security context of the node.
Note: This property exists on all nodes (HTML, XUL, SVG, MathML, etc.), but only if the script trying to use it has UniversalXPConnect privileges.
public function get nodePrincipal():nsIPrincipal
See also
DOM 1 Core nodeType | property |
nodeType:Number
[read-only] Introduced in: | DOM 1 Core |
Returns an integer code representing the type of the node.
public function get nodeType():Number
See also
var node = document.documentElement.firstChild; if(node.nodeType != Node.COMMENT_NODE) alert("You should comment your code well!");
nodeTypedValue | property |
nodeTypedValue:*
Non-standard (Microsoft)
Contains the node value expressed in its defined data type.
Note: This value depends on the value of the nodeType property of the IXMLDOMNode.
Note: The data type for this node is defined in its dataType Property. This property also depends on the value of the node type, in the nodeType property.
Note: Although you can explicitly set the nodeTypedValue property with a particular data type in the VARIANT, the set operation does not change the data type. The value in the VARIANT is coerced to the data type specified in the dataType property, and the set operation returns an error if the type coercion is not possible.
Value | Description |
---|---|
NODE_ATTRIBUTE | Returns the value in the data representation of the type specified in the schema for the attribute. (Data types are specified using the dt:dt attribute, and because attributes cannot be applied to attributes, the attribute's data type can be specified only in the schema.) If no type was specified, returns a string identical to the nodeValue property. If the new value is not of the type specified in the schema or cannot be coerced to the type specified in the schema, then an error occurs. |
NODE_CDATA_SECTION, NODE_COMMENT, NODE_DOCUMENT, NODE_DOCUMENT_FRAGMENT, NODE_DOCUMENT_TYPE, NODE_ENTITY, NODE_NOTATION, NODE_PROCESSING_INSTRUCTION | Returns a string that is equal to the nodeValue property. These node types do not have data types. |
NODE_ELEMENT | eturns the value in the data representation of the type specified on the element instance (using the dt:dt attribute) or specified in the schema. If no type was specified on the instance or in the schema, returns a string identical to the nodeValue property. If the element has an attribute data type, returns null. |
NODE_ENTITY_REFERENCE | Returns the value in the data representation of the type specified for the referenced entity. This is limited to entities with a single data type on the root level element of the subtree corresponding to the entity. If no data type was specified, returns a string identical to the nodeValue property. |
NODE_TEXT | Returns the value in the data representation of the type of the containing element. If the containing element was not typed, returns a string identical to the nodeValue property. |
Data Type Mapping
VARIANT returned | Corresponding element data type |
---|---|
VT_BSTR | string |
VT_BSTR | number |
VT_I4 | Int |
VT_CY | Fixed.14.4 |
VT_BOOL | Boolean |
VT_DATE | dateTime |
VT_DATE | dateTime.tz |
VT_DATE | Date |
VT_DATE | Time |
VT_DATE | Time.tz |
VT_I1 | i1 byte |
VT_I2 | i2 |
VT_I4 | i4, int |
VT_UI1 | ui1 |
VT_UI2 | ui2 |
VT_UI4 | ui4 |
VT_FLOAT | r4 |
VT_DOUBLE | r8, float |
VT_BSTR | uuid |
VT_ARRAY | bin.hex |
VT_ARRAY | bin.base64 |
public function get nodeTypedValue():*
public function set nodeTypedValue(value:any):void
See also
nodeTypeString | property |
nodeTypeString:DOMString
[read-only] Non-standard (Microsoft)
Returns the node type in string form.
public function get nodeTypeString():DOMString
See also
NODE_ATTRIBUTE == "attribute"
DOM 1 Core nodeValue | property |
nodeValue:DOMString
Introduced in: | DOM 1 Core |
Returns or sets the value of the current node.
Note: For the document itself, nodeValue returns null. For text, comment, and CDATA nodes, nodeValue returns the content of the node. For attribute nodes, the value of the attribute is returned.
Note: The following table shows the return values for different elements:
Interface | nodeValue |
---|---|
Attr | value of attribute |
CDATASection | content of the CDATA Section |
Comment | content of the comment |
Document | null |
DocumentFragment | null |
DocumentType | null |
Element | null |
Entity | null |
EntityReference | null |
Notation | null |
ProcessingInstruction | entire content excluding the target |
text | content of the text node |
Note: When nodeValue is defined to be null, setting it has no effect.
public function get nodeValue():DOMString
public function set nodeValue(value:DOMString):void
DOMException — NO_MODIFICATION_ALLOWED_ERR: Raised
when the node is readonly.
| |
DOMException — DOMSTRING_SIZE_ERR: Raised when it
would return more characters than fit in a DOMString variable
on the implementation platform.
|
See also
DOM 1 Core ownerDocument | property |
ownerDocument:Document
[read-only] Introduced in: | DOM 1 Core |
Modified in: | DOM 2 Core |
The Document object associated with this node. This is also the Document object used to create new nodes.
Note: When this node is a Document or a DocumentType which is not used with any Document yet, this is null.
public function get ownerDocument():Document
See also
// given a node "p", get the top-level HTML child // of the document object d = p.ownerDocument; html = d.documentElement;
DOM 1 Core parentNode | property |
parentNode:Node
[read-only] Introduced in: | DOM 1 Core |
Returns the parent of the specified node in the DOM tree.
Note: parentNode returns null for the following node types: Attr, Document, DocumentFragment, Entity, and Notation.
Note: It also returns null if the node has just been created and is not yet attached to the tree.
public function get parentNode():Node
See also
if (node.parentNode) { // remove a node from the tree, unless it's not in the tree already node.parentNode.removeChild(node); }
parsed | property |
parsed:Boolean
[read-only] Non-standard (Microsoft)
Indicates the parsed status of the node and child nodes.
Note: During asynchronous access, not all of the document tree may be available. Before performing some operations, such as Extensible Stylesheet Language Transformations (XSLT) or pattern-matching operations, it is useful to know whether the entire tree below this node is available for processing.
public function get parsed():Boolean
See also
DOM 2 Core prefix | property |
prefix:DOMString
Introduced in: | DOM 2 Core |
Returns the namespace prefix of the specified node, or null if no prefix is specified.
Note: This will only work when a namespace-aware parser is used, i.e. when a document is served with an XML mime-type. This will not work for HTML documents.
public function get prefix():DOMString
public function set prefix(value:DOMString):void
DOMException — INVALID_CHARACTER_ERR: Raised if the
specified prefix contains an illegal character according to the XML
version in use specified in the Document.xmlVersion attribute.
| |
DOMException — NO_MODIFICATION_ALLOWED_ERR: Raised if
this node is readonly.
| |
DOMException — NAMESPACE_ERR: Raised if the specified
prefix is malformed per the Namespaces in XML specification, if the
namespaceURI of this node is null, if the specified prefix is "xml"
and the namespaceURI of this node is different from
"http://www.w3.org/XML/1998/namespace", if this node is an attribute
and the specified prefix is "xmlns" and the namespaceURI of this node
is different from "http://www.w3.org/2000/xmlns/", or if this node is
an attribute and the qualifiedName of this node is "xmlns"
[XML Namespaces].
|
See also
<x:div onclick="alert(this.prefix)"/>
DOM 1 Core previousSibling | property |
previousSibling:Node
[read-only] Introduced in: | DOM 1 Core |
Returns the node immediately preceding the specified one in its parent's childNodes list, null if the specified node is the first in that list.
Note (Mozilla): Gecko-based browsers insert text nodes into a document to represent whitespace in the source markup. Therefore a node obtained for example via firstChild or previousSibling may refer to a whitespace text node, rather than the actual element the author intended to get.
Note: To navigate the opposite way through the child nodes list use element.nextSibling.
public function get previousSibling():Node
See also
// <a><b1 id="b1"/><b2 id="b2"/></a> alert(document.getElementById("b1").previousSibling); // null alert(document.getElementById("b2").previousSibling.id); // "b1"
specified | property |
specified:Boolean
[read-only] Non-standard (Microsoft)
Indicates whether the node (usually an attribute) is explicitly specified or derived from a default value in the document type definition (DTD) or schema.
Only returns true for attribute nodes if the attribute was specified directly on the element. Returns false for default attributes and all other node types.
public function get specified():Boolean
See also
text | property |
text:DOMString
Non-standard (Microsoft)
Represents the text content of the node or the concatenated text representing the node and its descendants.
Value | Description |
---|---|
NODE_ATTRIBUTE, NODE_DOCUMENT, NODE_ENTITY | Returns a string representing the value of the node. This is the concatenated text of all subnodes with entities expanded. |
NODE_CDATA_SECTION, NODE_COMMENT, NODE_PROCESSING_INSTRUCTION, NODE_TEXT | Returns the text contained in the node, which is the same as the nodeValue property. |
NODE_DOCUMENT_TYPE, NODE_NOTATION | Returns the empty string (""). These node types do not have associated text. |
NODE_DOCUMENT_FRAGMENT | Returns the text comprised of the concatenation of all descendant nodes. |
NODE_ELEMENT | Contains a string that represents the element content. Note that this will also include the text content from all child elements, concatenated in document order. For example, consider the following XML:
<count> <item>one</item> <item>two</item> <item>three</item> <item>four</item> </count> |
NODE_ENTITY_REFERENCE | Returns the string representation of the entity reference. |
Note: When concatenated, the text represents the contents of text or CDATA nodes. All concatenated text nodes are normalized according to xml:space attributes and the value of the preserveWhiteSpace switch. Concatenated CDATA text is not normalized. (Child nodes that contain NODE_COMMENT and NODE_PROCESSING_INSTRUCTION nodes are not concatenated.)
Note: Retrieves and sets the string representing the text contents of this node or the concatenated text representing this node and its descendants.
Note: For more precise control over text manipulation in an XML document, use the lower-level nodeValue property, which returns the raw text associated with a NODE_TEXT node.
public function get text():DOMString
public function set text(value:DOMString):void
See also
<root att=" 123 a < "> <a> a a </a> <!-- comment b --> <?pi pi c ?> <![CDATA[ cdata d ]]> e f </root>
The text property for the root element returns the following concatenated text.
"a a cdata d e f"
Note that the white space within the CDATA node is preserved.
DOM 3 Core textContent | property |
textContent:DOMString
Introduced in: | DOM 3 Core |
Gets or sets the text content of a node and its descendants.
Note: textContent returns null if the element is a document, a document type, or a notation. To grab all of the text and CDATA data for the whole document, one could usedocument.documentElement.textContent.
Note: If the node is a CDATA section, a comment, a processing instruction, or a text node, textContent returns the text inside this node (the nodeValue).
Note: For other node types, textContent returns the concatenation of the textContent attribute value of every child node, excluding comments and processing instruction nodes. This is an empty string if the node has no children.
Note: Setting this property on a node removes all of its children and replaces them with a single text node with the given value.
public function get textContent():DOMString
public function set textContent(value:DOMString):void
DOMException — NO_MODIFICATION_ALLOWED_ERR: Raised
when the node is readonly.
| |
DOMException — DOMSTRING_SIZE_ERR: Raised when it
would return more characters than fit in a DOMString variable on
the implementation platform.
|
See also
// Given the following HTML fragment: // <div id="divA">This is <span>some</span> text</div> // Get the text content: var text = document.getElementById("divA").textContent; // |text| is set to "This is some text". // Set the text content: document.getElementById("divA").textContent = "This is some text"; // The HTML for divA is now: // <div id="divA">This is some text</div>
xml | property |
xml:DOMString
[read-only] Non-standard (Microsoft)
Contains the XML representation of the node and all its descendants.
Note: The xml property always returns a Unicode string. That is, the xml property for DOMDocument converts the document from its original encoding to Unicode. As a result, the original encoding attribute is removed. For example, <?xml version="1.0" encoding="UTF-8"?> appears in the xml property as follows.
<?xml version="1.0"?>
If the original encoding was not removed by the xml property, the following line returns an error indicating the parser cannot switch from Unicode to UTF-8 encoding.
xmlDoc.loadxml(xmlDoc.xml);
If you use the save Method, the original encoding is preserved. For example, if you load a document in Microsoft® Windows® 1252 encoding, it will be saved in that format.
public function get xml():DOMString
See also
DOM 2 Events addEventListener | () | method |
public function addEventListener(type:DOMString, listener:EventListener, useCapture:Boolean):void
Introduced in: | DOM 2 Events |
Associates a function with a particular event and binds the event to the current node.
Parameters
type:DOMString — A string representing the event to bind, without the "on" prefix. For example, "click", "mousedown" etc.
| |
listener:EventListener — The function or method to associate with the event.
| |
useCapture:Boolean — Whether to bind the event as it is propagating towards the target node, (event Capture), or as the
event bubbles upwards from the target (event bubble). Set to true or false, respectively.
|
See also
function statusreport() { alert("document has loaded"); } if (window.addEventListener) { window.addEventListener("load", statusreport, false); //invoke function } window.onload = statusreport(); //function invoked again, since no event handler conflicts
DOM 3 Events addEventListenerNS | () | method |
public function addEventListenerNS(namespaceURI:DOMString, type:DOMString, listener:EventListener, useCapture:Boolean):void
Introduced in: | DOM 3 Events |
Registers an event listener, depending on the useCapture parameter, on the capture phase of the DOM event flow or its target and bubbling phases.
Parameters
namespaceURI:DOMString — Specifies the Event.namespaceURI associated with the event for which the user is registering.
| |
type:DOMString — A string representing the event to bind, without the "on" prefix. For example, "click", "mousedown" etc.
| |
listener:EventListener — The function or method to associate with the event.
| |
useCapture:Boolean — Whether to bind the event as it is propagating towards the target node, (event Capture), or as the
event bubbles upwards from the target (event bubble). Set to true or false, respectively.
|
See also
DOM 1 Core appendChild | () | method |
public function appendChild(element:Node):Node
Introduced in: | DOM 1 Core |
Modified in: | DOM 3 Core |
Adds a node to the end of the list of children of a specified parent node. If the node already exists it is removed from current parent node, then added to new parent node.
Note: If child is a reference to an existing node in the document, appendChild moves it from its current position to the new position (i.e. there is no requirement to remove the node from its parent node before appending it to some other node).
Note: This also means that a node can't be in two points of the document simultaneously. So if the node already has a parent, it is first removed, then appended at the new position.
Note: You can use cloneNode to make a copy of the node before appending it under the new parent. (Note that the copies made with cloneNode will not be automatically kept in sync.)
Note: This method is not allowed to move nodes between different documents. If you want to append node from a different document (for example to display results from AJAX request) you must first use importNode.
Note (IE6): In Microsoft Internet Explorer 6, This method now applies to the attribute object.
Note: When inserting a node tree under another node that has a different owner document, the ownerDocument property for each inserted node is changed to match the owner document of its new parent.
Note: When moving a node tree to another document, the content of all entity reference nodes contained therein is updated to conform to the new document. If the new document does not declare an entity that was moved into it, the entity reference will have no children, and the old content is removed. Existing references to nodes under the entity reference are still valid, but the node whose parent previously was the entity reference now has a null parent.
Parameters
element:Node — Object that specifies the element to append.
|
Node — Returns a reference to the element that is appended to the object.
|
DOMException — HIERARCHY_REQUEST_ERR: Raised if this
node is of a type that does not allow children of the type of the
newChild node, or if the node to append is one of this node's
ancestors or this node itself, or if this node is of type Document
and the DOM application attempts to append a second DocumentType or
Element node.
| |
DOMException — WRONG_DOCUMENT_ERR: Raised if newChild
was created from a different document than the one that created
this node.
| |
DOMException — NO_MODIFICATION_ALLOWED_ERR: Raised if
this node is readonly or if the previous parent of the node being
inserted is readonly.
| |
DOMException — NOT_SUPPORTED_ERR: if the newChild node
is a child of the Document node, this exception might be raised if
the DOM implementation doesn't support the removal of the
DocumentType child or Element child.
|
See also
// Create a new paragraph element, and append it to the end of the document body var p = document.createElement("p"); document.body.appendChild(p);
DOM 1 Core cloneNode | () | method |
public function cloneNode(cloneChildren:Boolean):Node
Introduced in: | DOM 1 Core |
Returns a duplicate of the current node.
Note: Cloning a node copies all of its attributes and their values.
Note: The duplicate node returned by cloneNode is not part of the document until it is added to another node that is part of the document using appendChild or a similar method. It also has no parent until it is appended to another node.
Note: If cloneChildren is set to false, none of the child nodes are cloned. Any text that the node contains is not cloned either, as it is contained in one or more child Text nodes.
Note: When you refer to the ID of a cloned element, a collection is returned.
Note: To clone a node for appending to a different document, use importNode instead.
Note (IE): If the node is the DOMDocument node, it is safer to clone the document using the save method, as follows. doc.save(doc2);
Parameters
cloneChildren:Boolean — FALSE, cloned objects do not include childNodes. TRUE, cloned objects include childNodes.
|
Node — Returns a reference to the newly created node.
|
See also
p = document.getElementById("para1"); p_prime = p.cloneNode(true);
DOM 3 Core compareDocumentPosition | () | method |
public function compareDocumentPosition(other:Node):Number
Introduced in: | DOM 3 Core |
Compares the position of the current node against another node in any other document.
Parameters
other:Node — The node that's being compared against.
|
Number — The return value is computed as the relationship that otherNode has
|
DOMException — NOT_SUPPORTED_ERR: when the compared
nodes are from different DOM implementations that do not coordinate
to return consistent implementation-specific results.
|
See also
var head = document.getElementsByTagName('head').item(0); var result = head.compareDocumentPosition(document.body); // result = Node.DOCUMENT_POSITION_FOLLOWING
DOM 2 Events dispatchEvent | () | method |
public function dispatchEvent(evt:Event):Boolean
Introduced in: | DOM 2 Events |
Modified in: | DOM 3 Events |
Dispatches an event to fire on a node artificially.
Note (IE): IE's equivalent of dispatchEvent() is fireEvent().
Parameters
evt:Event — The event to be dispatched.
|
Boolean — Indicates whether any of the listeners which handled the
event called Event.preventDefault(). If Event.preventDefault() was
called the returned value is false, else it is true.
|
See also
<div id="test" onclick="alert('hi')">Sample DIV.</div> <script type="text/javascript"> //Generate an artificial click event on "test". Fires alert("hi") var clickevent = document.createEvent("MouseEvents"); clickevent.initEvent("click", true, true); document.getElementById("test").dispatchEvent(myevent); </script>
DOM 3 Core getFeature | () | method |
public function getFeature(feature:DOMString, version:DOMString):DOMObject
Introduced in: | DOM 3 Core |
This method returns a specialized object which implements the specialized APIs of the specified feature and version, as specified in DOM Features. The specialized object may also be obtained by using binding-specific casting methods but is not necessarily expected to, as discussed in Mixed DOM Implementations. This method also allow the implementation to provide specialized objects which do not support the Node interface.
Parameters
feature:DOMString — The name of the feature requested. Note that any plus
sign "+" prepended to the name of the feature will be ignored since it
is not significant in the context of this method.
| |
version:DOMString — This is the version number of the feature to test.
|
DOMObject — Returns an object which implements the specialized APIs of the
specified feature and version, if any, or null if there is no object
which implements interfaces associated with that feature. If the
DOMObject returned by this method implements the Node interface, it must
delegate to the primary core Node and not return results inconsistent
with the primary core Node such as attributes, childNodes, etc.
|
See also
DOM 3 Core getUserData | () | method |
public function getUserData(key:DOMString):DOMUserData
Introduced in: | DOM 3 Core |
Retrieves 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.
Parameters
key:DOMString — The key the object is associated to.
|
DOMUserData — Returns the DOMUserData associated to the given key on this node,
or null if there was none.
|
See also
var d = document.setUserData('key', 15, null); alert(document.getUserData('key')); // 15
DOM 2 Core hasAttributes | () | method |
public function hasAttributes():Boolean
Introduced in: | DOM 2 Core |
Returns a boolean value of true or false, indicating if the current element has any attributes or not.
ReturnsBoolean — If the current element has any attributes or not.
|
See also
t1 = document.getElementById("table-data"); if (t1.hasAttributes()) { // do something with t1.attributes }
var result=document.getElementsByTagName("div")[0].hasAttributes();
DOM 1 Core hasChildNodes | () | method |
public function hasChildNodes():Boolean
Introduced in: | DOM 1 Core |
Returns a value that indicates whether the object has children.
Note: If the object contains HTML Elements or TextNodes, they can be accessed from the childNodes collection.
Note: element.hasChildNodes, without the parenthesises, will return the hasChildNodes Function, and not a Boolean.
Note (IE6): In Microsoft Internet Explorer 6, This method now applies to the attribute object.
ReturnsBoolean —
|
See also
var foo = document.getElementById("foo"); if (foo.hasChildNodes()) { foo.removeChild(foo.childNodes[0]); }
DOM 1 Core insertBefore | () | method |
public function insertBefore(newNode:Node, childNode:Node):Node
Introduced in: | DOM 1 Core |
Modified in: | DOM 3 Core |
Inserts the specified node before a reference element as a child of the current node.
Note: Do not specify the childNode parameter when inserting the first child node. If children already exist and you do not specify the childNode parameter, the oNewNode becomes the last child of the parent object.
Note (IE6): In Microsoft Internet Explorer 6, This method now applies to the attribute object.
Parameters
newNode:Node — The node to insert.
| |
childNode:Node — The node before which newNode is inserted.
|
Node — Returns a reference to the element that is inserted into the document.
|
DOMException — HIERARCHY_REQUEST_ERR: Raised if this
node is of a type that does not allow children of the type of the
newChild node, or if the node to insert is one of this node's
ancestors or this node itself, or if this node is of type Document
and the DOM application attempts to insert a second DocumentType
or Element node.
| |
DOMException — WRONG_DOCUMENT_ERR: Raised if newChild
was created from a different document than the one that created
this node.
| |
DOMException — NO_MODIFICATION_ALLOWED_ERR: Raised if
this node is readonly or if the parent of the node being inserted
is readonly.
| |
DOMException — NOT_FOUND_ERR: Raised if refChild is
not a child of this node.
| |
DOMException — NOT_SUPPORTED_ERR: if this node is of
type Document, this exception might be raised if the DOM
implementation doesn't support the insertion of a DocumentType or
Element node.
|
See also
<html> <head> <title>Gecko DOM insertBefore test</title> </head> <body> <div> <span id="childSpan">foo bar</span> </div> <script type="text/javascript"> // create an empty element node // without an ID, any attributes, or any content var sp1 = document.createElement("span"); // give it an id attribute called 'newSpan' sp1.setAttribute("id", "newSpan"); // create some content for the newly created element. var sp1_content = document.createTextNode("This is a new span element. "); // apply that content to the new element sp1.appendChild(sp1_content); var sp2 = document.getElementById("childSpan"); var parentDiv = sp2.parentNode; // insert the new element into the DOM before sp2 parentDiv.insertBefore(sp1, sp2); </script> </body> </html>
There is no insertAfter method, however it can be emulated using a combination of insertBefore and nextSibling.
From the above example, sp1 could be inserted after sp2 using:
parentDiv.insertBefore(sp1, sp2.nextSibling);
If sp2 does not have a next sibling it must be the last child—sp2.nextSibling will return null so sp1 will be inserted at the end of the child nodes list (i.e. immediately after sp2).
DOM 3 Core isDefaultNamespace | () | method |
public function isDefaultNamespace(namespaceURI:DOMString):Boolean
Introduced in: | DOM 3 Core |
Returns true if the namespace is the default namespace on the given node or false if not.
Parameters
namespaceURI:DOMString — The namespace against which the element will be checked.
|
Boolean — If the namespace is the default namespace on the given
node or false if not.
|
See also
var XULNS = "http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"; var el = document.getElementsByTagNameNS(XULNS, 'textbox')[0]; alert(el.isDefaultNamespace(XULNS)); // true
DOM 3 Core isEqualNode | () | method |
public function isEqualNode(arg:Node):Boolean
Introduced in: | DOM 3 Core |
Tests whether two nodes are equal.
This method tests for equality of nodes, not sameness (i.e., whether the two nodes are references to the same object) which can be tested with Node.isSameNode(). All nodes that are the same will also be equal, though the reverse may not be true. Two nodes are equal if and only if the following conditions are satisfied:
For two DocumentType nodes to be equal, the following conditions must also be satisfied:
On the other hand, the following do not affect equality: the ownerDocument, baseURI, and parentNode attributes, the specified attribute for Attr nodes, the schemaTypeInfo attribute for Attr and Element nodes, the Text.isElementContentWhitespace attribute for Text nodes, as well as any user data or event listeners registered on the nodes.
Note: As a general rule, anything not mentioned in the description above is not significant in consideration of equality checking. Note that future versions of this specification may take into account more attributes and implementations conform to this specification are expected to be updated accordingly.
Parameters
arg:Node — The node to compare equality with.
|
Boolean — Returns true if the nodes are equal, false otherwise.
|
See also
DOM 3 Core isSameNode | () | method |
public function isSameNode(other:Node):Boolean
Introduced in: | DOM 3 Core |
Returns whether this node is the same node as the given one. This method provides a way to determine whether two Node references returned by the implementation reference the same object. When two Node references are references to the same object, even if through a proxy, the references may be used completely interchangeably, such that all attributes have the same values and calling the same DOM method on either reference always has exactly the same effect.
Parameters
other:Node — The node to test against.
|
Boolean — Returns true if the nodes are the same, false otherwise.
|
See also
DOM 2 Core isSupported | () | method |
public function isSupported(feature:DOMString, version:DOMString):Boolean
Introduced in: | DOM 2 Core |
Tests whether the DOM implementation implements a specific feature and that feature is supported by this node.
Note: To check if any version of the DOM specification is supported, you can pass in null as the version instead of a string.
Parameters
feature:DOMString — name of the feature to test. This is the same name
which can be passed to the method hasFeature on DOMImplementation.
Possible values defined within the core DOM specification are listed
on the DOM Level 2 Conformance Section. The name of the feature to
test. This is the same name which can be passed to the method
hasFeature on DOMImplementation. Possible values defined within
the core DOM specification are listed on the DOM Level 2 Conformance Section.
| |
version:DOMString — This is the version number of the feature to test. In DOM
Level 2, version 1, this is the string 2.0. If the version is not specified,
supporting any version of the feature will cause the method to return true.
|
Boolean —
|
See also
// Get an element and check to see if its supports the DOM2 HTML Module <div id="doc"> </div> var main = document.getElementById('doc'); var output = main.isSupported('HTML', '2.0');
DOM 3 Core lookupNamespaceURI | () | method |
public function lookupNamespaceURI(prefix:DOMString):DOMString
Introduced in: | DOM 3 Core |
Takes a prefix and returns the namespaceURI associated with it on the given node if found (and null if not). Supplying null for the prefix will return the default namespace.
Note (Mozilla): Due to bug 312019, this method does not work with dynamically assigned namespaces (i.e., those set with Node.prefix).
Parameters
prefix:DOMString — The prefix to look for. If this parameter is null,
the method will return the default namespace URI if any.
|
DOMString — Returns the associated namespace URI or null if none is found.
|
See also
DOM 3 Core lookupPrefix | () | method |
public function lookupPrefix(namespaceURI:DOMString):DOMString
Introduced in: | DOM 3 Core |
Returns the prefix for a given namespaceURI if present, and null if not. When multiple prefixes are possible, the result is implementation-dependent.
Note (Mozilla): Due to bug 312019, this method does not work with dynamically assigned namespaces (i.e., those set with Node.prefix).
Parameters
namespaceURI:DOMString — The namespace URI to look for.
|
DOMString — Returns an associated namespace prefix if found or null if none is
found. If more than one prefix are associated to the namespace prefix, the
returned namespace prefix is implementation dependent.
|
See also
DOM 1 Core normalize | () | method |
public function normalize():void
Introduced in: | DOM 1 Core |
Modified in: | DOM 3 Core |
Puts the specified node and all of its subtree into a "normalized" form. In a normalized subtree, no text nodes in the subtree are empty and there are no adjacent text nodes.
Note (IE): By calling object.normalize before the subelements of an object are manipulated, you ensure that the document object model has a consistent structure. The normal form is useful for operations that require a consistent document tree structure, and it ensures that the document object model view is identical when saved and reloaded.
Note (IE): Adjacent CDATA sections will not be merged by the normalize method, allowing for an inconsistent object model when CDATA sections are present.
See also
DOM 1 Core removeChild | () | method |
public function removeChild(node:Node):Node
Introduced in: | DOM 1 Core |
Modified in: | DOM 3 Core |
Removes a child node from the object.
The node to be removed must be an immediate child of the parent object.
If child is actually not a child of the element node, the method throws an exception.
Note: The removed child node still exists in memory, but is no longer part of the DOM. You may reuse the removed node later in your code, via the oldChild object reference.
Note (IE6): In Microsoft Internet Explorer 6, This method now applies to the attribute object.
Parameters
node:Node — Specifies the element to be removed from the document.
|
Node — Returns a reference to the object that is removed.
|
DOMException — NO_MODIFICATION_ALLOWED_ERR: Raised if
this node is readonly.
| |
DOMException — NOT_FOUND_ERR: Raised if oldChild is not
a child of this node.
| |
DOMException — NOT_SUPPORTED_ERR: if this node is of
type Document, this exception might be raised if the DOM implementation
doesn't support the removal of the DocumentType child or the Element child.
|
See also
// <div id="top" align="center"> // <div id="nested"></div> // </div> var d = document.getElementById("top"); var d_nested = document.getElementById("nested"); var throwawayNode = d.removeChild(d_nested);
// remove all children from element var element = document.getElementById("top"); while (element.firstChild) { element.removeChild(element.firstChild); }
DOM 2 Events removeEventListener | () | method |
public function removeEventListener(type:DOMString, listener:EventListener, useCapture:Boolean):void
Introduced in: | DOM 2 Events |
Removes an event listener.
Calling removeEventListener with arguments which do not identify any currently registered EventListener on the EventTarget has no effect. The Event.namespaceURI for which the user registered the event listener is implied and is null.
Parameters
type:DOMString — Specifies the Event.type for which the user registered
the event listener.
| |
listener:EventListener — The EventListener to be removed.
| |
useCapture:Boolean — Specifies whether the EventListener being removed
was registered for the capture phase or not. If a listener was
registered twice, once for the capture phase and once for the target
and bubbling phases, each must be removed separately. Removal of an
event listener registered for the capture phase does not affect the
same event listener registered for the target and bubbling phases,
and vice versa.
|
See also
DOM 3 Events removeEventListenerNS | () | method |
public function removeEventListenerNS(namespaceURI:DOMString, type:DOMString, listener:EventListener, useCapture:Boolean):void
Introduced in: | DOM 3 Events |
Removes an event listener. Calling removeEventListenerNS with arguments which do not identify any currently registered EventListener on the EventTarget has no effect.
Parameters
namespaceURI:DOMString — Specifies the Event.namespaceURI associated with the event for which the user registered the event listener.
| |
type:DOMString — Specifies the Event.type for which the user registered
the event listener.
| |
listener:EventListener — The EventListener to be removed.
| |
useCapture:Boolean — Specifies whether the EventListener being removed
was registered for the capture phase or not. If a listener was
registered twice, once for the capture phase and once for the target
and bubbling phases, each must be removed separately. Removal of an
event listener registered for the capture phase does not affect the
same event listener registered for the target and bubbling phases,
and vice versa.
|
See also
DOM 1 Core replaceChild | () | method |
public function replaceChild(newNode:Node, childNode:Node):Node
Introduced in: | DOM 1 Core |
Modified in: | DOM 3 Core |
Replaces an existing child element with a new child element.
Parameters
newNode:Node — The new node to replace oldChild. If it already exists in the DOM, it is first removed.
| |
childNode:Node — Specifies the existing element to be replaced.
|
Node — Returns a reference to the object that is replaced.
|
DOMException — HIERARCHY_REQUEST_ERR: Raised if this
node is of a type that does not allow children of the type of the
newChild node, or if the node to put in is one of this node's
ancestors or this node itself, or if this node is of type Document
and the result of the replacement operation would add a second
DocumentType or Element on the Document node.
| |
DOMException — WRONG_DOCUMENT_ERR: Raised if newChild
was created from a different document than the one that created
this node.
| |
DOMException — NO_MODIFICATION_ALLOWED_ERR: Raised if
this node or the parent of the new node is readonly.
| |
DOMException — NOT_FOUND_ERR: Raised if oldChild is
not a child of this node.
| |
DOMException — NOT_SUPPORTED_ERR: if this node is of
type Document, this exception might be raised if the DOM implementation
doesn't support the replacement of the DocumentType child or Element child.
|
See also
// <div> // <span id="childSpan">foo bar</span> // </div> // create an empty element node // without an ID, any attributes, or any content var sp1 = document.createElement("span"); // give it an id attribute called 'newSpan' sp1.setAttribute("id", "newSpan"); // create some content for the new element. var sp1_content = document.createTextNode("new replacement span element."); // apply that content to the new element sp1.appendChild(sp1_content); // build a reference to the existing node to be replaced var sp2 = document.getElementById("childSpan"); var parentDiv = sp2.parentNode; // replace existing node sp2 with the new span element sp1 parentDiv.replaceChild(sp1, sp2);
selectNodes | () | method |
public function selectNodes(queryString:DOMString):NodeList
Non-standard (Microsoft)
Applies the specified pattern-matching operation to this node's context and returns the list of matching nodes as IXMLDOMNodeList.
Note (IE): This method is only valid if the XML Query Language (XQL) feature has been included in the operating system (OS). If a call to this method is made and XQL is not supported, an error message will be returned.
Note (IE): The selectSingleNode method is similar to the selectNodes method, but returns only the first matching node rather than the list of all matching nodes.
Parameters
queryString:DOMString — A XSLPattern or XPath query that is to be applied to the context defined by this node. The value of the
SelectionLanguage internal property (flag) determines whether an XSLPattern or XPath query is used. By default, the queryString is
an XSLPattern query. The SelectionLanguage internal property (flag) can be set with the setProperty Method.
|
NodeList — Returns a collection of nodes selected by an XSL Pattern or XPath query. If no nodes are selected, an empty collection is returned.
|
See also
selectSingleNode | () | method |
public function selectSingleNode(queryString:DOMString):Node
Non-standard (Microsoft)
Applies the specified pattern-matching operation to this node's context and returns the first matching node.
Note (IE): This method is only valid if the XML Query Language (XQL) feature has been included in the OS. If a call to this method is made and XQL is not supported, an error message will be returned.
Note (IE): The selectSingleNode method is similar to the selectNodes Method, but returns only the first matching node rather than the list of all matching nodes.
Parameters
queryString:DOMString — A Extensible Stylesheet Language (XSL) or XPath query that is to be applied to the context defined by
this node. The value of the SelectionLanguage internal property (flag) determines whether an XSL or XPath query is used.
By default, the expression is an XSL pattern query. The SelectionLanguage internal property (flag) can be set with the
setProperty method.
|
Node — Returns the first node that matches the XSL or XPath query. If no nodes match the query, it returns Null.
|
See also
DOM 3 Core setUserData | () | method |
public function setUserData(key:DOMString, data:DOMUserData, handler:UserDataHandler):DOMUserData
Introduced in: | DOM 3 Core |
Associate an object to a key on this node. The object can later be retrieved from this node by calling getUserData with the same key.
Allows a user to attach data to an element, without needing to modify the DOM. Note that such data will not be preserved when imported via importNode, as with cloneNode() and renameNode() operations (though adoptNode does preserve the information), and equality tests in isEqualNode() do not consider user data in making the assessment.
This method offers the convenience of associating data with specific nodes without needing to alter the structure of a document and in a standard fashion, but it also means that extra steps may need to be taken if one wishes to serialize the information or include the information upon clone, import, or rename operations.
Parameters
key:DOMString — The key to associate the object to.
| |
data:DOMUserData — The object to associate to the given key, or null to remove any existing association to that key.
| |
handler:UserDataHandler — The handler to associate to that key, or null.
|
DOMUserData — Returns the DOMUserData previously associated to the given key on this node, or null if there was none.
|
See also
var d = document.implementation.createDocument('', 'test', null); d.documentElement.setUserData('key', 15, {handle:function (o, k, d, s, ds) {alert(o+'::'+k+'::'+d+'::'+s+'::'+ds)}}); // 2::key::15::[object Element]::[object Element] alert(d.documentElement.getUserData('key')); // 15 var e = document.importNode(d.documentElement, true); // causes handler to be called alert(e.getUserData('key')); // null since user data is not copied
transformNode | () | method |
public function transformNode(styleSheet:Node):DOMString
Non-standard (Microsoft)
Processes this node and its children using the supplied Extensible Stylesheet Language Transformations (XSLT) style sheet and returns the resulting transformation.
Note (IE): This method is only valid if the XSLT feature has been included in the operating system (OS). If a call to this method is made and XSLT is not supported, an error message will be returned.
Note (IE): The stylesheet parameter must be either a DOMDocument node, in which case the document is assumed to be an Extensible Stylesheet Language (XSL) style sheet, or a Document Object Model (DOM) node in the XSL style sheet, in which case this node is treated as a stand-alone style sheet fragment.
Note (IE): The source node defines a context in which the style sheet operates, but navigation outside this scope is allowed. For example, a style sheet can use the id function to access other parts of the document.
Note (IE): This method supports both stand-alone and embedded style sheets and also provides the ability to run a localized style sheet fragment against a particular source node.
Parameters
styleSheet:Node — Valid XML document or DOM node that consists of XSLT elements that direct the transformation of this node.
|
DOMString — Returns a string that contains the product of the transformation of this XML document based on the XSLT style sheet.
|
See also
transformNodeToObject | () | method |
public function transformNodeToObject(styleSheet:Node, outputObject:*):void
Non-standard (Microsoft)
Processes this node and its children using the supplied Extensible Stylesheet Language Transformations (XSLT) style sheet and returns the resulting transformation.
Note (IE): This method is only valid if the XSLT feature has been included in the operating system (OS). If a call to this method is made and XSLT is not supported, an error message will be returned.
Note (IE): The stylesheet parameter must be either a DOMDocument node, in which case the document is assumed to be an XSLT style sheet, or a Document Object Model (DOM) node in the XSLT style sheet, in which case this node is treated as a stand-alone style sheet fragment.
Note (IE): The source node defines a context in which the style sheet operates, but navigation outside this scope is allowed. For example, a style sheet can use the id function to access other parts of the document.
Note (IE): This method supports both stand-alone and embedded style sheets and also provides the ability to run a localized style sheet fragment against a particular source node.
Note (IE): The transformNodeToObject method always generates a Unicode byte-order mark, which means it cannot be used in conjunction with other Active Server Pages (ASP) Response.Write or Response.BinaryWrite calls.
Parameters
styleSheet:Node — Valid XML document or DOM node that consists of XSLT elements that direct the transformation of this node.
| |
outputObject:* — On return, contains the product of the transformation of this XML document based on the XSLT style sheet.
If the variant represents the DOMDocument object, the document is built according to its properties and its child nodes are
replaced during this transformation process. The XML transformation can also be sent to a stream.
|
See also
DOM 1 Core ATTRIBUTE_NODE | Constant |
public static const ATTRIBUTE_NODE:Number = 2
Introduced in: | DOM 1 Core |
The node is an Attr.
The node represents an attribute of an element. An attribute node can have the following child node types: Text and EntityReference. An attribute does not appear as the child node of any other node type; note that it is not considered a child node of an element.
See also
DOM 1 Core CDATA_SECTION_NODE | Constant |
public static const CDATA_SECTION_NODE:Number = 4
Introduced in: | DOM 1 Core |
The node is a CDATASection.
The node represents a CDATA section in the XML source. CDATA sections are used to escape blocks of text that would otherwise be recognized as markup. A CDATA section node cannot have any child nodes. A CDATA section node can appear as the child of the DocumentFragment, EntityReference, and Element nodes.
See also
DOM 1 Core COMMENT_NODE | Constant |
public static const COMMENT_NODE:Number = 8
Introduced in: | DOM 1 Core |
The node is a Comment.
The node represents a comment in the XML document. A comment node cannot have any child nodes. A comment node can appear as the child of Document, DocumentFragment, Element, and EntityReference nodes.
See also
DOM 1 Core DOCUMENT_FRAGMENT_NODE | Constant |
public static const DOCUMENT_FRAGMENT_NODE:Number = 11
Introduced in: | DOM 1 Core |
The node is a DocumentFragment.
The node represents a document fragment. A document fragment node associates a node or subtree with a document without actually being contained within the document. A document fragment node can have the following child node types: Element, ProcessingInstruction, Comment, Text, CDATASection, and EntityReference. A DocumentFragment node cannot appear as the child of any node types.
See also
DOM 1 Core DOCUMENT_NODE | Constant |
public static const DOCUMENT_NODE:Number = 9
Introduced in: | DOM 1 Core |
The node is a Document.
The node represents a document object, which, as the root of the document tree, provides access to the entire XML document. It is created using the progID "Msxml2.DOMDocument", or through a data island using <XML> or <SCRIPT LANGUAGE=XML>. A document node can have the following child node types: Element (maximum of one), ProcessingInstruction, Comment, and DocumentType. A document node cannot appear as the child of any node types.
See also
DOM 3 Core DOCUMENT_POSITION_CONTAINED_BY | Constant |
public static const DOCUMENT_POSITION_CONTAINED_BY:Number = 16
Introduced in: | DOM 3 Core |
The node is contained by the reference node. A node which is contained is always following, too.
See also
DOM 3 Core DOCUMENT_POSITION_CONTAINS | Constant |
public static const DOCUMENT_POSITION_CONTAINS:Number = 8
Introduced in: | DOM 3 Core |
The node contains the reference node. A node which contains is always preceding, too.
See also
DOM 3 Core DOCUMENT_POSITION_DISCONNECTED | Constant |
public static const DOCUMENT_POSITION_DISCONNECTED:Number = 1
Introduced in: | DOM 3 Core |
The two nodes are disconnected. Order between disconnected nodes is always implementation-specific.
See also
DOM 3 Core DOCUMENT_POSITION_FOLLOWING | Constant |
public static const DOCUMENT_POSITION_FOLLOWING:Number = 4
Introduced in: | DOM 3 Core |
The node follows the reference node.
See also
DOM 3 Core DOCUMENT_POSITION_IMPLEMENTATION_SPECIFIC | Constant |
public static const DOCUMENT_POSITION_IMPLEMENTATION_SPECIFIC:Number = 32
Introduced in: | DOM 3 Core |
The determination of preceding versus following is implementation-specific.
See also
DOM 3 Core DOCUMENT_POSITION_PRECEDING | Constant |
public static const DOCUMENT_POSITION_PRECEDING:Number = 2
Introduced in: | DOM 3 Core |
The second node precedes the reference node.
See also
DOM 1 Core DOCUMENT_TYPE_NODE | Constant |
public static const DOCUMENT_TYPE_NODE:Number = 10
Introduced in: | DOM 1 Core |
The node is a DocumentType.
The node represents the document type declaration, indicated by the <!DOCTYPE > tag. A document type node can have the following child node types: Notation and Entity. A document type node can appear as the child of the Document node.
See also
DOM 1 Core ELEMENT_NODE | Constant |
public static const ELEMENT_NODE:Number = 1
Introduced in: | DOM 1 Core |
The node is an Element.
The node represents an element. An element node can have the following child node types: Element, Text, Comment, ProcessingInstruction, CDATASection, and EntityReference. An element node can be the child of the Document, DocumentFragment, EntityReference, and Element nodes.
See also
DOM 1 Core ENTITY_NODE | Constant |
public static const ENTITY_NODE:Number = 6
Introduced in: | DOM 1 Core |
The node is an Entity.
The node represents an expanded entity. An entity node can have child nodes that represent the expanded entity (for example, Text and EntityReference nodes). An entity node can appear as the child of the DocumentType node.
See also
DOM 1 Core ENTITY_REFERENCE_NODE | Constant |
public static const ENTITY_REFERENCE_NODE:Number = 5
Introduced in: | DOM 1 Core |
The node is an EntityReference.
The node represents a reference to an entity in the XML document. This applies to all entities, including character entity references. An entity reference node can have the following child node types: Element, ProcessingInstruction, Comment, Text, CDATASection, and EntityReference. An entity reference node can appear as the child of the Attribute, DocumentFragment, Element, and EntityReference nodes.
See also
DOM 1 Core NOTATION_NODE | Constant |
public static const NOTATION_NODE:Number = 12
Introduced in: | DOM 1 Core |
The node is a Notation.
A node represents a notation in the document type declaration. A notation node cannot have any child nodes. A notation node can appear as the child of the DocumentType node.
See also
DOM 1 Core PROCESSING_INSTRUCTION_NODE | Constant |
public static const PROCESSING_INSTRUCTION_NODE:Number = 7
Introduced in: | DOM 1 Core |
The node is a ProcessingInstruction.
The node represents a processing instruction from the XML document. A processing instruction node cannot have any child nodes. A processing instruction node can appear as the child of the Document, DocumentFragment, Element, and EntityReference nodes.
See also
DOM 1 Core TEXT_NODE | Constant |
public static const TEXT_NODE:Number = 3
Introduced in: | DOM 1 Core |
The node is a Text node.
The node represents the text content of a tag. A text node cannot have any child nodes. A text node can appear as the child node of the Attribute, DocumentFragment, Element, and EntityReference nodes.
See also