Skip to content

Instantly share code, notes, and snippets.

@rbaty-barr
Created November 2, 2018 13:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rbaty-barr/1c52500bc7ba36e1c65a66c67e9823bd to your computer and use it in GitHub Desktop.
Save rbaty-barr/1c52500bc7ba36e1c65a66c67e9823bd to your computer and use it in GitHub Desktop.
JavaScript to make compliant tables
$(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>");
});
@rbaty-barr
Copy link
Author

This script may evolve over time, but here is a first pass that is working for us on xylembenefits.com presently.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment