Class pv.Dom.Node
Represents a Node in the W3C Document Object Model.
Defined in: Dom.js.
Constructor Attributes | Constructor Name and Description |
---|---|
pv.Dom.Node(value)
Constructs a DOM node for the specified value.
|
Field Attributes | Field Name and Description |
---|---|
The first child, which is null for leaf nodes.
|
|
The last child, which is null for leaf nodes.
|
|
The next sibling node, which is null for the last child.
|
|
The parent node, which is null for root nodes.
|
|
The previous sibling node, which is null for the first child.
|
Method Attributes | Method Name and Description |
---|---|
appendChild(n)
Appends the specified child node to this node.
|
|
insertBefore(n, r)
Inserts the specified child n before the given reference child
r of this node.
|
|
nodes()
Returns all descendants of this node in preorder traversal.
|
|
removeChild(n)
Removes the specified child node from this node.
|
|
replaceChild(n, r)
Replaces the specified child r of this node with the node n.
|
|
reverse()
Reverses all sibling nodes.
|
|
sort(f)
Sorts child nodes of this node, and all descendent nodes recursively, using
the specified comparator function f.
|
|
toggle(recursive)
Toggles the child nodes of this node.
|
|
visitAfter(f)
Visits each node in the tree in postorder traversal, applying the specified
function f.
|
|
visitBefore(f)
Visits each node in the tree in preorder traversal, applying the specified
function f.
|
Class Detail
pv.Dom.Node(value)
Constructs a DOM node for the specified value. Instances of this class are
not typically created directly; instead they are generated from a JavaScript
map using the pv.Dom operator.
- Parameters:
- value
Field Detail
{pv.Dom.Node}
firstChild
The first child, which is null for leaf nodes.
{pv.Dom.Node}
lastChild
The last child, which is null for leaf nodes.
{pv.Dom.Node}
nextSibling
The next sibling node, which is null for the last child.
{pv.Dom.Node}
parentNode
The parent node, which is null for root nodes.
{pv.Dom.Node}
previousSibling
The previous sibling node, which is null for the first child.
Method Detail
{pv.Dom.Node}
appendChild(n)
Appends the specified child node to this node. If the specified child is
already part of the DOM, the child is first removed before being added to
this node.
- Parameters:
- n
- Returns:
- {pv.Dom.Node} the appended child.
{pv.Dom.Node}
insertBefore(n, r)
Inserts the specified child n before the given reference child
r of this node. If r is null, this method is equivalent to
#appendChild. If n is already part of the DOM, it is first
removed before being inserted.
- Parameters:
- n
- r
- Throws:
- Error if r is non-null and not a child of this node.
- Returns:
- {pv.Dom.Node} the inserted child.
nodes()
Returns all descendants of this node in preorder traversal.
{pv.Dom.Node}
removeChild(n)
Removes the specified child node from this node.
- Parameters:
- n
- Throws:
- Error if the specified child is not a child of this node.
- Returns:
- {pv.Dom.Node} the removed child.
replaceChild(n, r)
Replaces the specified child r of this node with the node n. If
n is already part of the DOM, it is first removed before being added.
- Parameters:
- n
- r
- Throws:
- Error if r is not a child of this node.
reverse()
Reverses all sibling nodes.
- Returns:
- this.
sort(f)
Sorts child nodes of this node, and all descendent nodes recursively, using
the specified comparator function f. The comparator function is
passed two nodes to compare.
Note: during the sort operation, the comparator function should not rely on the tree being well-formed; the values of previousSibling and nextSibling for the nodes being compared are not defined during the sort operation.
- Parameters:
- {function} f
- a comparator function.
- Returns:
- this.
toggle(recursive)
Toggles the child nodes of this node. If this node is not yet toggled, this
method removes all child nodes and appends them to a new toggled
array attribute on this node. Otherwise, if this node is toggled, this method
re-adds all toggled child nodes and deletes the toggled attribute.
This method has no effect if the node has no child nodes.
- Parameters:
- {boolean} recursive Optional
- whether the toggle should apply to descendants.
visitAfter(f)
Visits each node in the tree in postorder traversal, applying the specified
function f. The arguments to the function are:
- The current node.
- The current depth, starting at 0 for the root node.
- Parameters:
- {function} f
- a function to apply to each node.
visitBefore(f)
Visits each node in the tree in preorder traversal, applying the specified
function f. The arguments to the function are:
- The current node.
- The current depth, starting at 0 for the root node.
- Parameters:
- {function} f
- a function to apply to each node.