I am retrieving HTML from a remote host with the following jQuery code
var loadUrl = "URL.html";
$("#result")
.html(ajax_load)
.load(loadUrl + " table.schedule");
Which gives me the following HTML
Name | column A | column B |
---|---|---|
1 | A1 | B1 |
2 | A2 | B2 |
Name | column C | column D |
---|---|---|
3 | C1 | D1 |
4 | C2 | D2 |
The number of TR & TDs can change, and I want to retrieve the data for column A,B,C,D and "transform" the HTML into a list format like the following XML.
A1
A2
B1
B2
C1
C2
D1
D2
I have tried the following code, which provides me with the first column data, but it also concatenates all the TDs from both Tables into one list.
$("#load_get").click(function(){
var xml = "";
$("#result")
.find("tr").each(function() {
xml += "";
xml += $(this).find("td").eq(1).html() + "\n";
xml += "";
} );
xml += "";
alert(xml);
});
Please help.
EDIT
Thank you Polarblau, Federic & Albert for your responses. They helped a lot, sorry to change the goal, but if i could modify the scenario slightly.
This is the same HTML, except it has a header in the first TR, there are two tables and the first column is ignored as before.
ignore | Header1 | header2 |
---|---|---|
ignore | A1 | B1 |
ignore | A2 | B2 |
//second table
The XML i wish to have, needs to grab the Header(TH) and use it in the TD loop to set the name attribute, like so.
A1
A2
B1
B2
//second table xml
I tried unsuccessfully, to modify your solutions to achieve this.