Created
September 29, 2012 15:11
-
-
Save jaredcunha/3804292 to your computer and use it in GitHub Desktop.
This script creates a fake table heading from the <thead> for responsive tables that collapse to a vertical orientation in narrow viewports
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
/* Responsive Table =================================================================*/ | |
$(document).ready(function(){ | |
/*Declare headings*/ | |
var theHeads = $('.vert-collapse thead th'); | |
var allHeadersSaved = new Array(); | |
/*Get content of all table headers, add to array*/ | |
theHeads.each(function() { | |
var headerContent = $(this).text(); | |
allHeadersSaved.push(headerContent); | |
}); | |
/*should get th or td*/ | |
var tableData = $('.vert-collapse tbody tr > *'); | |
/*counter*/ | |
var n = 0; | |
/*Check create fake head for each table cell*/ | |
/*Once counter reachers number of headers used, it starts over*/ | |
tableData.each(function(){ | |
$(this).prepend('<span class="fake-head">'+allHeadersSaved[n]+'</span>'); | |
if (n < (allHeadersSaved.length - 1)){ | |
n++ | |
} | |
else {n=0;} | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment