Skip to content

Instantly share code, notes, and snippets.

@steve10287
Created June 11, 2015 10:25
Show Gist options
  • Save steve10287/d93a9f4aa12533d26ca1 to your computer and use it in GitHub Desktop.
Save steve10287/d93a9f4aa12533d26ca1 to your computer and use it in GitHub Desktop.
responsivetable
/***
Convert finance tables into responsive tables
Loop thru each table header or in this cast tr:first child
Then add the title for the table header to the the td elements as a data attribute
Then in css: use :before {content: attr(data-content)}
***/
$('table').each(function()
{
var nthChild = 1;
$(this).find('tbody > tr:first-child > td').each(function(e)
{
var title = this.innerText;
$(this)
.parent().parent().parent()
.find('tbody tr:not(:first-child) td:nth-child(' + nthChild + ')').attr('data-content', title);
nthChild++
})
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment