Last active
September 9, 2020 18:57
-
-
Save jpen365/f34bbff7d9db99f912e1e75193071718 to your computer and use it in GitHub Desktop.
Get table headings to use with responsive table layout
This file contains hidden or 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
/* Credits: | |
This bit of code: Exis | exisweb.net/responsive-tables-in-wordpress | |
Original idea: Dudley Storey | codepen.io/dudleystorey/pen/Geprd */ | |
var headertext = []; | |
var headers = document.querySelectorAll("thead"); | |
var tablebody = document.querySelectorAll("tbody"); | |
for (var i = 0; i < headers.length; i++) { | |
headertext[i]=[]; | |
for (var j = 0, headrow; headrow = headers[i].rows[0].cells[j]; j++) { | |
var current = headrow; | |
headertext[i].push(current.textContent); | |
} | |
} | |
for (var h = 0, tbody; tbody = tablebody[h]; h++) { | |
for (var i = 0, row; row = tbody.rows[i]; i++) { | |
for (var j = 0, col; col = row.cells[j]; j++) { | |
col.setAttribute("data-th", headertext[h][j]); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi @jpen365,
How to exclude certain tables?
For example how to exclude all tables with this class
is-style-stripes
this table: