Tuesday, November 26, 2013

Find children inside a DOM node in JavaScript.

Here we are starting with a table which has one row (inside a tbody) containing numerous cells. Each table detail has first a div in it and then another element. We are collecting just the divs into an array!

var colorKeys = [];
var tableRows = legend.childNodes[0].childNodes[0].childNodes;
for (i = 0; i < tableRows.length; i++) {
   colorKeys.push(tableRows[i].childNodes[0]);
}

No comments:

Post a Comment