Pythoner1234 Pythoner1234 - 1 year ago 80
HTML Question

How to read a list of html tables in JavaScript

I have a list of HTML tables given by pandas data frame in the format of:

list_html =
[<table border="1" class="dataframe">
<tr style="text-align: right;">
</tr>, ... , ... ]

I am trying to visualize this data in an html page and could not do it. I do not have enough experience in web development. My goal is to use JavaScript to loop through each item the list and visualize them below each other in html. It would be great if anybody can help!

This is what I tried so far, its probably completely wrong:

var list_html = list_html // list of html codes as a javascript variable.
var arrayLength = analysis.length;
for (var i in list_html) {
document.getElementById("analysis_1").innerHTML = list_html[i];

Answer Source

Given a valid array of strings list_html (actually list_html is not a valid array of strings, since the markup in each entry is not wrapped in quotes) and a container in the DOM with id "analysis_1" it's simply a matter of:

var container = document.getElementById('analysis_1');
for (var i = 0; i < list_html.length; i++) {
    container.innerHTML += list_html[i];


well... in your scenario there is no need at all for a loop, you can simply inject a single string by joining the elements in the array:

document.getElementById('analysis_1').innerHTML = list_html.join('');

fast and simple! :)

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download