Elementals.js

Latest Version: 2.0 RC 3 14 March 2017

Method _.nodeReplace

Replaces all content of an element with new content. This is functionally similar to Element.innerHTML = newContent; except this is performed using the DOM, does not accept markup, but can be passed a new DOM object.

Calling Convention:
_.nodeReplace(Element, newContent)
Parameters:
Element
Target to replace the content of.
newContent
If a string, it will be placed as a new text node. If an object it will be added to the DOM.
Returns:
Nothing

Example

HTML

<ul id="test">
	<li>First</li>
	<li id="test">Second</li>
	<li>Third</li>
</ul>

JavaScript

var test = document.getElementById('test');
_.nodeReplace(test, _.make('li', { content : 'All by myself' }));

All three existing LI are removed from the list and replaced by <li>All by myself</li>