function makeTableFluid(container) { function processTable(tableNode) { var $table = $(tableNode); if ($table.data('isFluid')) { return; } $table.data('isFluid', true); var i, j, ic, row, cell; var headerText = [], headers = tableNode.querySelectorAll("th"), tableBody = tableNode.querySelector("tbody"); for (i = 0, ic = headers.length; i < ic; i++) { var current = headers[i]; current.innerHTML = current.innerHTML.replace(/()+/g, " "); headerText.push(current.textContent.replace(/\r?\n|\r/, "")); } for (i = 0; row = tableBody.rows[i]; i++) { for (j = 0; cell = row.cells[j]; j++) { if (headerText[j] != undefined) { cell.setAttribute("data-th", headerText[j]); } $(cell).wrapInner(''); } } } container = $(container); if (container.is('table')) { processTable(container.get(0)); } else { container.each(function (idx, node) { processTable(node); }); } } $(document).ready(function () { makeTableFluid('.tbl-fluid'); });