Created
November 2, 2018 13:18
-
-
Save rbaty-barr/1c52500bc7ba36e1c65a66c67e9823bd to your computer and use it in GitHub Desktop.
JavaScript to make compliant tables
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$(document).ready(function () { | |
$("table").each(function(){ | |
var thisTable = $(this); | |
thisTable.attr("border","").removeAttr("style").addClass("table table-striped"); | |
$("tr").removeAttr("style"); | |
// $("td").removeAttr("style"); | |
var firstRow = thisTable.find('tr:first-child'); | |
firstRow.children('td').each(function() { | |
var colSpan = $(this).attr("colspan"); | |
var tdw = $(this).css("width"); | |
var html = $(this).html(); | |
// console.log(colSpan); | |
$(this).replaceWith('<th colspan=' + colSpan + ' style= "width:' + tdw + ';">' + html + '</th>'); | |
}); | |
firstRow.replaceWith(function(i,html){ | |
return '<thead>' + html + '</thead>'; | |
}); | |
var theHead = thisTable.find("thead"); | |
theHead.detach(); | |
thisTable.prepend(theHead); | |
}); | |
$("table").wrap("<div class='table-responsive'></div>"); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This script may evolve over time, but here is a first pass that is working for us on xylembenefits.com presently.