Skip to content
This repository was archived by the owner on Jan 13, 2022. It is now read-only.

dom.array

oatkiller edited this page Sep 13, 2010 · 1 revision

get an array from a collection of nodes like you’d get from .childNodes or getElementsByTagName etc

(function () {

var my_div = document.createElement('div');
my_div.innerHTML = '<span>hi</span><p>a para</p>';

// throws an error
my_div.childNodes.push() // error, can't push childNodes because its not an array


// get an array from those child nodes
var my_child_nodes = o.dom.array(my_div.childNodes);

// now this works because my_child_nodes is an array
my_child_nodes.push('anything');

// my_child_nodes isn't live
my_div.innerHTML = '';

my_child_nodes[0]; // still has nodes. this is the span

})();
Clone this wiki locally