- Source:
Methods
replaceNode(target, node) → {HTMLElement}
Replaces a node with another one.
If the node is not an element, the parameter is treated as source and a node is created automatically based on that.
The target node needs a parent node for this function to work.
Parameters:
Name | Type | Description |
---|---|---|
target |
HTMLElement | the element to replace |
node |
HTMLElement | String | the node to replace the target with |
- Source:
Throws:
error if target is not an HTMLElement or does not have a parent
Returns:
the replacement node
- Type
- HTMLElement
Example
replaceNode(document.querySelector('.hint'), newHintElement);
replaceNode(document.querySelector('.hint'), '<p class="hint">Sale tomorrow!</p>');