Skip to main content

enode.swap()

Method enode.swap() is used to change the HTML element associated with the current enode, and also replace that element with the new one on DOM if already rendered.

Using this method will change the value of enode.element, also replace the previous HTML element if already rendered on DOM.

tip

In case of expecting changes not reflected on DOM when assigning a new HTML element to an enode, use enode.set().

Syntax

JavaScript
enode.swap(enodeTarget: Binh.ElementNode)

Parameters

element

Return value

The current enode with a new associated HTML element from enodeTarget.

Examples

JavaScript
var content = new Binh.ElementNode(document.createElement('div'));
var text = new Binh.ElementNode(document.createElement('span'));

document.body.appendChild(content.element);

console.log(document.body.childNodes);
// Output: NodeList(1) [<div></div>]

content.swap(text);

console.log(document.body.childNodes);
// Output: NodeList(1) [<span></span>]