OracleJavaScript API Reference for Oracle ADF Faces

 

SUMMARY: FIELD | CONSTR | METHOD    DETAIL: FIELD | CONSTR | METHOD

org.w3c.dom.core
Class Node

org.ecmascript.object.Object
   |
   +--org.w3c.dom.core.Node
Direct Known Subclasses:
Attr, CharacterData, Document, DocumentFragment, DocumentType, Element, Entity, EntityReference, Notation, ProcessingInstruction

public abstract class Node
extends Object
The Node interface is the primary datatype for the entire Document Object Model. It represents a single node in the document tree. While all objects implementing the Node interface expose methods for dealing with children, not all objects implementing the Node interface may have children. For example, Text nodes may not have children, and adding children to such nodes results in a DOMException being raised.

The attributes nodeName, nodeValue and attributes are included as a mechanism to get at node information without casting down to the specific derived interface. In cases where there is no obvious mapping of these attributes for a specific nodeType (e.g., nodeValue for an Element or attributes for a Comment), this returns null. Note that the specialized interfaces may contain additional and more convenient mechanisms to get and set the relevant information.

Note that this object is implemented and supported by the web browser and results of its use may vary.



Field Summary

public static Number
ATTRIBUTE_NODE
This constant is of type Number and its value is 2.
public NamedNodeMap
attributes
A NamedNodeMap containing the attributes of this node (if it is an Element ) or null otherwise.
public static Number
CDATA_SECTION_NODE
This constant is of type Number and its value is 4.
public NodeList
childNodes
A {@link NamedNodeMap} that contains all children of this node.
public static Number
COMMENT_NODE
This constant is of type Number and its value is 8.
public static Number
DOCUMENT_FRAGMENT_NODE
This constant is of type Number and its value is 11.
public static Number
DOCUMENT_NODE
This constant is of type Number and its value is 9.
public static Number
DOCUMENT_TYPE_NODE
This constant is of type Number and its value is 10.
public static Number
ELEMENT_NODE
This constant is of type Number and its value is 1.
public static Number
ENTITY_NODE
This constant is of type Number and its value is 6.
public static Number
ENTITY_REFERENCE_NODE
This constant is of type Number and its value is 5.
public Node
firstChild
The first child of this node.
public Node
lastChild
The last child of this node.
public String
localName
Returns the local part of the qualified name of this node.
public String
namespaceURI
The namespace URI of this node, or null if it is unspecified.
public Node
nextSibling
The node immediatly following this node.
public String
nodeName
The name of this node, depending on its type.
public Number
nodeType
A code representing the type of the underlying object.
public String
nodeValue
The value of this node, depending on its type; see the table above.
public static Number
NOTATION_NODE
This constant is of type Number and its value is 12.
public Document
ownerDocument
The {@link Document} object associated with this node.
public Node
parentNode
The parent of this node.
public String
prefix
The namespace prefix of this node, or null if it is unspecified.
public Node
previousSibling
The node immediately preceding this node.
public static Number
PROCESSING_INSTRUCTION_NODE
This constant is of type Number and its value is 7.
public static Number
TEXT_NODE
This constant is of type Number and its value is 3.


Fields inherited from org.ecmascript.object.Object

constructor, prototype


Method Summary

public Node
appendChild(Node newChild)
Adds the node newChild to the end of the list of children of this node.
public Node
cloneNode(Boolean deep)
Returns a duplicate of this node, i.e., serves as a generic copy constructor for nodes.
public Boolean
hasAttributes()
Returns whether this node (if it is an element) has any attributes.
public Boolean
hasChildNodes()
Returns whether this node has any children.
public Node
insertBefore(Node newChild, Node refChild)
Inserts the node newChild before the existing child node refChild.
public Boolean
isSupported(String feature)
Tests whether the DOM implementation implements a specific feature and that feature is supported by this node.
public void
normalize()
Puts all Text nodes in the full depth of the sub-tree underneath this Node, including attribute nodes, into a "normal" form where only structure (e.g., elements, comments, processing instructions, CDATA sections, and entity references) separates {@link Text} nodes, i.e., there are neither adjacent {@link Text} nodes nor empty {@link Text} nodes.
public Node
removeChild(Node oldChild)
Removes the child node indicated by oldChild from the list of children, and returns it.
public Node
replaceChild(Node newNode, Node oldNode)
Replaces the child node oldChild with newChild in the list of children, and returns the oldChild node.


Field Detail


ATTRIBUTE_NODE

public static Number ATTRIBUTE_NODE

This constant is of type Number and its value is 2.

This is a readonly constant.

attributes

public NamedNodeMap attributes

A NamedNodeMap containing the attributes of this node (if it is an Element ) or null otherwise.

This is a readonly attribute

Example:
<div id="doc">
<div>
Text in the first DIV.
</div>
<div id="DDD" class="secondClass">
Some text in the second DIV.
</div>
<div class="thirdClass">
Some text and <span id="SSS">element</span> in the third DIV.
</div>
<div class="fourthClass">
We can try <i>another elements</i>.
It will be much more <b>interesting</b>.
</div>
<div>
Text in the last DIV.
</div>
</div>
JavaScript:

var main = document.getElementById('doc');
var attrNode = main.childNodes[3].attributes;
var output = attrNode.length;

CDATA_SECTION_NODE

public static Number CDATA_SECTION_NODE

This constant is of type Number and its value is 4.

This is a readonly constant.

childNodes

public NodeList childNodes

A NamedNodeMap that contains all children of this node. If there are no children, this is a NodeList containing no nodes.

This is a readonly attribute

Example:
<div id="doc">
<div>
Text in the first DIV.
</div>
<div >
Some text in the second DIV.
</div>
<div class="thirdClass">
Some text and <span >element</span> in the third DIV.
</div>
<div class="fourthClass">
We can try <i>another elements</i>.
It will be much more <b>interesting</b>.
</div>
<div>
Text in the last DIV.
</div>
</div>
JavaScript:
var main = document.getElementById('doc');
var output1 = main.childNodes.length;
var output2 = main.childNodes[0].nodeType;

COMMENT_NODE

public static Number COMMENT_NODE

This constant is of type Number and its value is 8.

This is a readonly constant.

DOCUMENT_FRAGMENT_NODE

public static Number DOCUMENT_FRAGMENT_NODE

This constant is of type Number and its value is 11.

This is a readonly constant.

DOCUMENT_NODE

public static Number DOCUMENT_NODE

This constant is of type Number and its value is 9.

This is a readonly constant.

DOCUMENT_TYPE_NODE

public static Number DOCUMENT_TYPE_NODE

This constant is of type Number and its value is 10.

This is a readonly constant.

ELEMENT_NODE

public static Number ELEMENT_NODE

This constant is of type Number and its value is 1.

This is a readonly constant.

ENTITY_NODE

public static Number ENTITY_NODE

This constant is of type Number and its value is 6.

This is a readonly constant.

ENTITY_REFERENCE_NODE

public static Number ENTITY_REFERENCE_NODE

This constant is of type Number and its value is 5.

This is a readonly constant.

firstChild

public Node firstChild

The first child of this node. If there is no such node, this returns null.

This is a readonly attribute

Example:
<div id="doc">
<div>
Text in the first DIV.
</div>
<div >
Some text in the second DIV.
</div>
<div class="thirdClass">
Some text and <span >element</span> in the third DIV.
</div>
<div class="fourthClass">
We can try <i>another elements</i>.
It will be much more <b>interesting</b>.
</div>
<div>
Text in the last DIV.
</div>
</div>
JavaScript:
var main = document.getElementById('doc');
var output = main.firstChild.nodeName;

lastChild

public Node lastChild

The last child of this node. If there is no such node, this returns null.

This is a readonly attribute

Example:
<div id="doc">
<div>
Text in the first DIV.
</div>
<div >
Some text in the second DIV.
</div>
<div class="thirdClass">
Some text and <span >element</span> in the third DIV.
</div>
<div class="fourthClass">
We can try <i>another elements</i>.
It will be much more <b>interesting</b>.
</div>
<div>
Text in the last DIV.
</div>
</div>
JavaScript:
var main = document.getElementById('doc');
var output = main.lastChild.nodeName;

localName

public String localName

Returns the local part of the qualified name of this node. For nodes of any type other than ELEMENT_NODE and ATTRIBUTE_NODE and nodes created with a DOM Level 1 method, such as createElement from the Document interface, this is always null.

This is a readonly attribute

Introduced in DOM Level 2.

Example:
<div  xmlns:svg="http://www.w3.org/2000/svg">
<div>
Text in the first DIV.
</div>
<svg:svg id="logo" xmlns:xlink="http://www.w3.org/1999/xlink" width="200" height="60">
<svg:g style="fill:#3399cc; font-size:36pt; font-family:'dialog'; font-weight: bold">
<svg:a xlink:type="simple" xlink:href="http://www.zvon.org">
<svg:text x="50%" y="65%" text-anchor="middle">ZVON.org</svg:text>
</svg:a>
</svg:g>
</svg:svg>
<apply xmlns="http://www.w3.org/1998/Math/MathML">
<int/>
<bvar>
<ci> x </ci>
</bvar>
<interval>
<ci> a </ci>
<ci> b </ci>
</interval>
<apply>
<cos/>
<ci> x &lt/ci>
</apply>
</apply>
<div>
Text in the last DIV.
</div>
</div>
JavaScript:
var elem = document.getElementsByTagName('int')[0];
var output = elem.localName;

namespaceURI

public String namespaceURI

The namespace URI of this node, or null if it is unspecified. 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. For nodes of any type other than ELEMENT_NODE and ATTRIBUTE_NODE and nodes created with a DOM Level 1 method, such as createElement from the Document interface, this is always null.

Note: Per the Namespaces in XML Specification [Namespaces] an attribute does not inherit its namespace from the element it is attached to. If an attribute is not explicitly given a namespace, it simply has no namespace.

This is a readonly attribute

Introduced in DOM Level 2.

Example:
<div  xmlns:svg="http://www.w3.org/2000/svg">
<div>
Text in the first DIV.
</div>
<svg:svg >
<svg:g style="fill:#3399cc; font-size:36pt; font-family:'dialog'; font-weight: bold">
<svg:a xlink:type="simple" xlink:href="http://www.zvon.org">
<svg:text x="50%" y="65%" text-anchor="middle">ZVON.org</svg:text>
</svg:a>
</svg:g>
</svg:svg>
<apply xmlns="http://www.w3.org/1998/Math/MathML">
<int/>
<bvar>
<ci> x </ci>
</bvar>
<interval>
<ci> a </ci>
<ci> b </ci>
</interval>
<apply>
<cos/>
<ci> x &lt/ci>
</apply>
</apply>
<div>
Text in the last DIV.
</div>
</div>
JavaScript:
var elem = document.getElementsByTagName('int')[0];
var output = elem.namespaceURI;

nextSibling

public Node nextSibling

The node immediatly following this node. If there is no such node, this returns null.

This is a readonly attribute

Example:
<div >
<div>
Text in the first DIV.
</div>
<div >
Some text in the second DIV.
</div>
<div class="thirdClass">
Some text and <span >element</span> in the third DIV.
</div>
<div class="fourthClass">
We can try <i>another elements</i>.
It will be much more <b>interesting</b>.
</div>
<div>
Text in the last DIV.
</div>
</div>
JavaScript:
var elem = document.getElementById('SSS');
var output = elem.nextSibling.nodeValue;

nodeName

public String nodeName

The name of this node, depending on its type.

This is a readonly attribute

Example:
<div >
<div>
Text in the first DIV.
</div>
<div >
Some text in the second DIV.
</div>
<div class="thirdClass">
Some text and <span >element</span> in the third DIV.
</div>
<div class="fourthClass">
We can try <i>another elements</i>.
It will be much more <b>interesting</b>.
</div>
<div>
Text in the last DIV.
</div>
</div>
JavaScript:
var main = document.getElementById('doc');
var output1 = main.nodeName;
var output2 = document.getElementById('SSS').nodeName;

nodeType

public Number nodeType

A code representing the type of the underlying object.

This is a readonly attribute

Example:
<div >
<div>
Text in the first DIV.
</div>
<div >
Some text in the second DIV.
</div>
<div class="thirdClass">
Some text and <span >element</span> in the third DIV.
</div>
<div class="fourthClass">
We can try <i>another elements</i>.
It will be much more <b>interesting</b>.
</div>
<div>
Text in the last DIV.
</div>
</div>
JavaScript:
var elem = document.getElementById('DDD');
var output1 = elem.nodeType;
var output2 = elem.firstChild.nodeType;

nodeValue

public String nodeValue

The value of this node, depending on its type; see the table above. When it is defined to be null, setting it has no effect.

Example:
<div >
<div>
Text in the first DIV.
</div>
<div >
Some text in the second DIV.
</div>
<div class="thirdClass">
Some text and <span >element</span> in the third DIV.
</div>
<div class="fourthClass">
We can try <i>another elements</i>.
It will be much more <b>interesting</b>.
</div>
<div>
Text in the last DIV.
</div>
</div>
JavaScript:
var output = document.getElementById('DDD').firstChild.nodeValue;

NOTATION_NODE

public static Number NOTATION_NODE

This constant is of type Number and its value is 12.

This is a readonly constant.

ownerDocument

public Document ownerDocument

The Document object associated with this node. This is also the Document object used to create new nodes. When this node is a Document or a DocumentType which is not used with any Document yet, this is null.

This is a readonly attribute

Introduced in DOM Level 2.

Example:
<div >
<div>
Text in the first DIV.
</div>
<div >
Some text in the second DIV.
</div>
<div class="thirdClass">
Some text and <span >element</span> in the third DIV.
</div>
<div class="fourthClass">
We can try <i>another elements</i>.
It will be much more <b>interesting</b>.
</div>
<div>
Text in the last DIV.
</div>
</div>
JavaScript:
var main = document.getElementById('doc');
var output = main.ownerDocument.documentElement.nodeName;

parentNode

public Node parentNode

The parent of this node. All nodes, except Attr, Document, DocumentFragment, Entity and Notation may have a parent. However, if a node has just been created and not yet added to the tree, or if it has been removed from the tree, this is null.

This is a readonly attribute

Example:
<div >
<div>
Text in the first DIV.
</div>
<div >
Some text in the second DIV.
</div>
<div class="thirdClass">
Some text and <span >element</span> in the third DIV.
</div>
<div class="fourthClass">
We can try <i>another elements</i>.
It will be much more <b>interesting</b>.
</div>
<div>
Text in the last DIV.
</div>
</div>
JavaScript:
var elem = document.getElementById('SSS');
var output = elem.nextSibling.nodeValue;

prefix

public String prefix

The namespace prefix of this node, or null if it is unspecified.

This is a readonly attribute

Introduced in DOM Level 2.

Example:
<div  xmlns:svg="http://www.w3.org/2000/svg">
<div>
Text in the first DIV.
</div>
<svg:svg >
<svg:g style="fill:#3399cc; font-size:36pt; font-family:'dialog'; font-weight: bold">
<svg:a xlink:type="simple" xlink:href="http://www.zvon.org">
<svg:text x="50%" y="65%" text-anchor="middle">ZVON.org</svg:text>
</svg:a>
</svg:g>
</svg:svg>
<apply xmlns="http://www.w3.org/1998/Math/MathML">
<int/>
<bvar>
<ci> x </ci>
</bvar>
<interval>
<ci> a </ci>
<ci> b </ci>
</interval>
<apply>
<cos/>
<ci> x &lt/ci>
</apply>
</apply>
<div>
Text in the last DIV.
</div>
</div>
JavaScript:
var main = document.getElementById('doc');
var output1 = main.nodeName;
var output2 = document.getElementById('SSS').nodeName;

previousSibling

public Node previousSibling

The node immediately preceding this node. If there is no such node, this returns null.

This is a readonly attribute

Example:
<div >
<div>
Text in the first DIV.
</div>
<div >
Some text in the second DIV.
</div>
<div class="thirdClass">
Some text and <span >element</span> in the third DIV.
</div>
<div class="fourthClass">
We can try <i>another elements</i>.
It will be much more <b>interesting</b>.
</div>
<div>
Text in the last DIV.
</div>
</div>
JavaScript:
var elem = document.getElementById('SSS');
var output = elem.previousSibling.nodeValue;

PROCESSING_INSTRUCTION_NODE

public static Number PROCESSING_INSTRUCTION_NODE

This constant is of type Number and its value is 7.

This is a readonly constant.

TEXT_NODE

public static Number TEXT_NODE

This constant is of type Number and its value is 3.

This is a readonly constant.

Method Detail


appendChild

public Node appendChild(Node newChild)

Adds the node newChild to the end of the list of children of this node. If the newChild is already in the tree, it is first removed.

Example:
<div >
<div>
Text in the first DIV.
</div>
<div >
Some text in the second DIV.
</div>
<div class="thirdClass">
Some text and <span >element</span> in the third DIV.
</div>
<div class="fourthClass">
We can try <i>another elements</i>.
It will be much more <b>interesting</b>.
</div>
<div>
Text in the last DIV.
</div>
</div>
JavaScript:
var main = document.getElementById('doc');
main.appendChild(main.childNodes[1]);
var output = main.lastChild.firstChild.nodeValue;

Parameters:
newChild  -  The node to add. If it is a DocumentFragment object, the entire contents of the document fragment are moved into the child list of this node.
Return:
Node - The node added
Throws:
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.
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.

cloneNode

public Node cloneNode(Boolean deep)

Returns a duplicate of this node, i.e., serves as a generic copy constructor for nodes. The duplicate node has no parent; (parentNode is null.). Cloning an Element copies all attributes and their values, including those generated by the XML processor to represent defaulted attributes, but this method does not copy any text it contains unless it is a deep clone, since the text is contained in a child Text node. Cloning an Attribute directly, as opposed to be cloned as part of an Element cloning operation, returns a specified attribute (specified is true). Cloning any other type of node simply returns a copy of this node.

Note that cloning an immutable subtree results in a mutable copy, but the children of an EntityReference clone are readonly. In addition, clones of unspecified Attr nodes are specified. And, cloning Document, DocumentType, Entity, and {&link Notation} nodes is implementation dependent.

Example:
<div >
<div>
Text in the first DIV.
</div>
<div >
Some text in the second DIV.
</div>
<div class="thirdClass">
Some text and <span >element</span> in the third DIV.
</div>
<div class="fourthClass">
We can try <i>another elements</i>.
It will be much more <b>interesting</b>.
</div>
<div>
Text in the last DIV.
</div>
</div>
JavaScript:
var main = document.getElementById('doc');
var elem = main.childNodes[3];
var returns = elem.cloneNode(true);
var output = returns.firstChild.nodeValue;

Parameters:
deep  -  If true, recursively clone the subtree under the specified node; if false, clone only the node itself (and its attributes, if it is an Element).
Return:
Node - The duplicate node

hasAttributes

public Boolean hasAttributes()

Returns whether this node (if it is an element) has any attributes.

Introduced in DOM Level 2.

Example:
<div >
<div>
Text in the first DIV.
</div>
<div >
Some text in the second DIV.
</div>
<div class="thirdClass">
Some text and <span >element</span> in the third DIV.
</div>
<div class="fourthClass">
We can try <i>another elements</i>.
It will be much more <b>interesting</b>.
</div>
<div>
Text in the last DIV.
</div>
</div>
JavaScript:
var elem1 = document.getElementById('doc');
var output1 = elem1.hasAttributes();
var tmp = elem1.getElementsByTagName('div');
var elem2 = tmp[tmp.length-1];
var output2 = elem2.hasAttributes();

Return:
Boolean - True if this node has any attributes, false otherwise.

hasChildNodes

public Boolean hasChildNodes()

Returns whether this node has any children.

Example:
<div >
<div>
Text in the first DIV.
</div>
<div >
Some text in the second DIV.
</div>
<div class="thirdClass">
Some text and <span >element</span> in the third DIV.
</div>
<div class="fourthClass">
We can try <i>another elements</i>.
It will be much more <b>interesting</b>.
</div>
<div>
Text in the last DIV.
</div>
</div>
JavaScript:
var elem1 = document.getElementById('doc');
var output1 = elem1.hasAttributes();
var tmp = elem1.getElementsByTagName('div');
var elem2 = tmp[tmp.length-1];
var output2 = elem2.hasAttributes();

Return:
Boolean - True if this node has any children, false otherwise.

insertBefore

public Node insertBefore(Node newChild,
                         Node refChild)

Inserts the node newChild before the existing child node refChild. If refChild is null, insert newChild at the end of the list of children. If newChild is a DocumentFragment object, all of its children are inserted, in the same order, before refChild. If the newChild is already in the tree, it is first removed.

Example:
<div >
<div>
Text in the first DIV.
</div>
<div >
Some text in the second DIV.
</div>
<div class="thirdClass">
Some text and <span >element</span> in the third DIV.
</div>
<div class="fourthClass">
We can try <i>another elements</i>.
It will be much more <b>interesting</b>.
</div>
<div>
Text in the last DIV.
</div>
</div>
JavaScript:
var main = document.getElementById('doc');
main.insertBefore(document.getElementById('DDD'), main.firstChild);
var output = main.firstChild.firstChild.nodeValue;

Parameters:
newChild  -  The node to insert.
refChild  -  The reference node, i.e., the node before which the new node must be inserted.
Return:
Node - The node being inserted.
Throws:
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.
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.

isSupported

public Boolean isSupported(String feature)

Tests whether the DOM implementation implements a specific feature and that feature is supported by this node.

Introduced in DOM Level 2.

Example:
<div >
<div>
Text in the first DIV.
</div>
<div >
Some text in the second DIV.
</div>
<div class="thirdClass">
Some text and <span >element</span> in the third DIV.
</div>
<div class="fourthClass">
We can try <i>another elements</i>.
It will be much more <b>interesting</b>.
</div>
<div>
Text in the last DIV.
</div>
</div>
JavaScript:

var main = document.getElementById('doc');
var output = main.isSupported('HTML', '1.0');

Parameters:
feature  -  The name of the feature to test. This is the same name which can be passed to the method DOMImplementation.hasFeature(String, String) on DOMImplementation.
Return:
Boolean - Returns true if the specified feature is supported on this node, false otherwise.

normalize

public void normalize()

Puts all Text nodes in the full depth of the sub-tree underneath this Node, including attribute nodes, into a "normal" form where only structure (e.g., elements, comments, processing instructions, CDATA sections, and entity references) separates Text nodes, i.e., there are neither adjacent Text nodes nor empty Text nodes. This can be used to ensure that the DOM view of a document is the same as if it were saved and re-loaded, and is useful when operations (such as XPointer [XPointer] lookups) that depend on a particular document tree structure are to be used.

Note: In cases where the document contains CDATASection, the normalize operation alone may not be sufficient, since XPointers do not differentiate between Text nodes and CDATASection nodes.

Modified in DOM Level 2.

Example:
<div >></div>
JavaScript:

var main = document.getElementById('doc');
var output1 = main.childNodes.length;
var textNode1 = document.createTextNode('This is some text.');
var textNode2 = document.createTextNode('This is another text.');
main.appendChild(textNode1);
main.appendChild(textNode2);
var output2 = main.childNodes.length;
main.normalize();
var output3 = main.childNodes.length;

Return:
void - null

removeChild

public Node removeChild(Node oldChild)

Removes the child node indicated by oldChild from the list of children, and returns it.

Example:
<div >
<div>
Text in the first DIV.
</div>
<div >
Some text in the second DIV.
</div>
<div class="thirdClass">
Some text and <span >element</span> in the third DIV.
</div>
<div class="fourthClass">
We can try <i>another elements</i>.
It will be much more <b>interesting</b>.
</div>
<div>
Text in the last DIV.
</div>
</div>
JavaScript:

var elem = document.getElementById('SSS');
var output1 = elem.firstChild.nodeValue;
elem.removeChild(elem.firstChild);
var output2 = elem.firstChild;

Parameters:
oldChild  -  The node being removed.
Return:
Node - The node removed.
Throws:
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.

replaceChild

public Node replaceChild(Node newNode,
                         Node oldNode)

Replaces the child node oldChild with newChild in the list of children, and returns the oldChild node. If newChild is a DocumentFragment object, oldChild is replaced by all of the DocumentFragment children, which are inserted in the same order. If the newChild is already in the tree, it is first removed.

Example:
<div >
<div>
Text in the first DIV.
</div>
<div >
Some text in the second DIV.
</div>
<div class="thirdClass">
Some text and <span >element</span> in the third DIV.
</div>
<div class="fourthClass">
We can try <i>another elements</i>.
It will be much more <b>interesting</b>.
</div>
<div>
Text in the last DIV.
</div>
</div>
JavaScript:

var elem = document.getElementById('DDD');
elem.replaceChild(document.getElementById('SSS').firstChild, elem.firstChild);
var output = elem.firstChild.nodeValue;

Parameters:
newNode  -  The new node to put in the child list.
oldNode  -  The node being replaced in the list.
Return:
Node - The node replaced.
Throws:
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.
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.

SUMMARY: FIELD | CONSTR | METHOD    DETAIL: FIELD | CONSTR | METHOD

 

Generated on 2011.04.27 02:28 UTC
Copyright (c) 1998, 2011, Oracle and/or its affiliates. All rights reserved.