WorknHardr
asked on
Loop Table Get All Text Not Working Well?
I have a table like so:
<tbody><tr><td id="589" class="btn btn-primary"><label>tarts< /label><tr ><td>class : Article</td></tr><tr><td>c ase: Accusative</td></tr></td>< /tr></tbod y>
And need to get the Text from each element. I have this code which returns too many results like so in FireFox console:
0: Array[3]
0: "tartsclass: Articlecase: Accusative" //yes it's run together like this
1; "class: Article"
2. "case: Accusative"
length: 3
1: Array[1]
0: "class: Article"
length: 1
Array[1]
0: "class: Accusative"
length: 1
My goal is to extract the text and build a Json string somehow...
[my code]
function getTableData(table) {
var data = [];
table.find('tr').each(func tion (rowIndex, r) {
var cols = [];
$(this).find('th,td').each (function (colIndex, c) {
cols.push(c.textContent);
});
data.push(cols);
});
return data;
}
[Usage]
getTableData($('#table1 table:last'));
<tbody><tr><td id="589" class="btn btn-primary"><label>tarts<
And need to get the Text from each element. I have this code which returns too many results like so in FireFox console:
0: Array[3]
0: "tartsclass: Articlecase: Accusative" //yes it's run together like this
1; "class: Article"
2. "case: Accusative"
length: 3
1: Array[1]
0: "class: Article"
length: 1
Array[1]
0: "class: Accusative"
length: 1
My goal is to extract the text and build a Json string somehow...
[my code]
function getTableData(table) {
var data = [];
table.find('tr').each(func
var cols = [];
$(this).find('th,td').each
cols.push(c.textContent);
});
data.push(cols);
});
return data;
}
[Usage]
getTableData($('#table1 table:last'));
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
The html has nested TR's inside TR's which is invalid html.
ASKER
thx, also got the table appends working great...
ASKER