Namespace $.dom.Node
Holds the DOM Node methods.
Defined in: core-dom.js.
| Constructor Attributes | Constructor Name and Description |
|---|---|
|
Holds the DOM Node methods.
|
| Method Attributes | Method Name and Description |
|---|---|
| <static> |
$.dom.Node.appendTo(target)
Append the current node to the target node.
|
| <static> |
$.dom.Node.insertAfter(new_node, ref_node)
Insert the specified node after a reference node to the current node.
|
| <static> |
$.dom.Node.prependChild(child)
Insert a new node as the first child to the current node.
|
| <static> |
$.dom.Node.prependTo(target)
Prepend the current node to the target node.
|
| <static> |
$.dom.Node.removeFirstChild()
Remove the first child from the current node.
|
| <static> |
$.dom.Node.removeLastChild()
Remove the last child from the current node.
|
By default, the global Node.prototype object is extended to contain all the methods defined in this namespace.
All of these methods use their this object. As such, you need to pass the correct this object.
In the examples provided for each method we will assume that the objects
defined are already extended. Thus code like
node.prependChild(child) can be written
directly. Such code can be read as "add the node child as a new
child to the node node, making sure it's the first child".
The current node is added to the list of children of the target node, becoming the last child.
var elem = document.createElement('div');
// Add the element to the body.
elem.appendTo(document.body);
- Parameters:
- {Node} target
- The target node where to append the current node.
- Throws:
- {TypeError}
- If target is not an instance of Node.
- Returns:
- {Node} The node that was appended.
The new_node will be added as a child of the current node, after the ref_node.
This method works like the native node.insertBefore()
method, which is actually used in the implementation.
var elem = document.createElement('div'),
ref = $('#foo');
document.body.insertAfter(elem, ref);
- Parameters:
- {Node} new_node
- The new node to insert as a child.
- {Node} ref_node
- The reference child node after which you want to insert the given new child node. If this argument is null, the new node is simply appended as a child, becoming the last in the list of children.
- Throws:
- {TypeError}
- If new_node is not an instance of Node.
- Returns:
- {Node} The node that was inserted.
var elem = document.createElement('div');
// Insert the element as the first child to the document.body.
document.body.prependChild(elem);
- Parameters:
- {Node} child
- The node to prepend as a child.
- Throws:
- {TypeError}
- If child is not an instance of Node.
- Returns:
- {Node} The prepended child node.
The current node is added to the list of children of the target node, becoming the first child.
var elem = document.createElement('div');
// Add the element to the body.
elem.prependTo(document.body);
- Parameters:
- {Node} target
- The target node where to prepend the current node.
- Throws:
- {TypeError}
- If target is not an instance of Node.
- Returns:
- {Node} The node that was prepended.
// Remove the first child from the document.body.
document.body.removeFirstChild();
- Returns:
- {Node|null} The removed child node, or null if nothing was removed.
// Remove the last child from the document.body.
document.body.removeLastChild();
- Returns:
- {Node|null} The removed child node, or null if nothing was removed.