Iterate over div tables and their elements?

If I have a div resthat contains N table elements with Y div with id eye-dinside them.

How would I iterate over them for each table, getting eye-d.innerHTML?

NOTE. eye-dis unique. There are many tables in 1 eye-d.

Example eye-d

<div id="eye-d"><table border="0" cellpadding="2" cellspacing="1" class="list"><tbody><tr class="table_text">​…​</tr><tr><td class="odd">​…​</td><td class="odd">​ABC</td><td class="odd">​N/A​</td></tr></tbody></table></div>

As requested .. paraphrased ...

I have 1 div with id eye-d, then I have many tables ... each of these tables has many divs with a class odd. I want .innerHTMLfor oddfor each table inside eye-d.

+3
source share
3 answers

Your identifier is not unique.

You cannot have more than one <div>with an identifier "eye-d".

, name . .

<div class="eye-d"> ... </div>

[[Edit]]

div , $("#eye-d table .odd") ( jQuery)

raw JS, :

var div = document.getElementById("eye-d");
var tables = [];
recurse(res.childNodes, function(el) {
    if (el.nodeName.toLowerCase() === "table") {
        tables.push(el);
    }
});
// array of innerHTML of odd divs.
var oddDivs = [];
for (var i = 0, ii = tables.length; i < ii; i++) {
    recurse(tables[i].childNodes, function(el) {
        if (el.className.indexOf("odd") > 0) {
            oddDivs.push(el.innerHTML);
        }
    });
}

function recurse(nodeList, do) {
    for (var i = 0, ii = nodeList.length; i < ii; i++) {
        do(nodeList[i]);
        if (nodeList[i].childNodes.length > 0) {
            recurse(nodeList[i].childNodes, do);
        }
    }
}

Recurse node do , . , .

+3

Y divs eye-d, eye-follow a * d * igit/number, , while (Y--) document.getElementById('eye-'+Y).innerHTML=...

0

As I understand it, you have:
1. Div with identifier eye-d.
2. There are several tables inside this div.
3. You want to get each table and view its innerHTML.

var allTables = document.getElementById('eye-d').getElementsByTagName('table');  
for(i in allTables){ alert(allTables[i].innerHTML); }
0
source

All Articles