I have a website with a lot of posts with <table>
and a new responsive layout.
When big table elements (lot of content) are opened on mobile devices, even with max-width: 100% or other CSS tricks, they get bigger than the screen.
The solution is append tables in a overflow: scroll <div>
, but I can't edit all the post content, so I want to do that with pure Javascript. jQuery not allowed.
The objetive is:
- Get all
<table>
elements of the page that are inside#post
- Get their content
- Append that content in a
<div class="table_div">
in the same place that the<table>
is - Remove old
table
elements (the ones that are not inside.table_div
)
I already can get all content from table elements and remove the tables, but the part of the code that supposedly should append table content in .table_div do not work.
Part of my code so far:
var post = document.getElementById('post'),
tables = post.getElementsByTagName('table');
for(var i=0; i<tables.length; i++) {
var table = tables[i];
var table_content = table.innerHTML,
table_div = document.createElement('div');
tables.remove();
table_div.appendChild(table);
table_div.className = 'table_div';
document.appendChild(table_div);
}
Full code: http://jsfiddle.net/hmaesta/6mambr93/
Please, help with just pure Javascript. Thank you.