I have an array of arrays which contain HTML elements like <a>
I would like to convert to a table but my problem is that HTML is displayed as raw text.
First I supposed it was a problem with hidden double quotes so I replace them with .replace()
cell.appendChild(document.createTextNode(x[i][j].replace(/"/g, "")));
But it looks like HTML is corretly formated in the Chrome DevTools DOM element :
<td><a href='http://website.org/prod4'>Product4</a></td>
Could you please tell me what should I do to display HTML elements in my table ?
var orderArray = [
["1", "29-Aug-2012", "Product1", "client1"],
["2", "29-Aug-2012", "Product2", "client2"],
["3", "29-Aug-2012", "Product3", "client3"],
["4", "29-Aug-2012", "<a href='http://website.org/prod/'>Product4</a>", "client4"],
["5", "29-Aug-2012", "Product5", "client5"]
];
function display() {
// get handle on div
var table = document.createElement("table");
for (var i = 0; i < orderArray.length; i++) {
var row = table.insertRow();
for (var j = 0; j < orderArray[i].length; j++) {
var cell = row.insertCell();
cell.appendChild(document.createTextNode(orderArray[i][j]));
}
}
return table;
}
var container = document.getElementById('container');
container.appendChild(display());
I use the code proposed by Bergi in this question : how to display array values inside <table> tag?
Thank you,