Created
September 28, 2022 15:14
-
-
Save Archie22is/34298569cc2804e66d00c02cc1c9bc20 to your computer and use it in GitHub Desktop.
Wrap and unwrap tables using jQuery based on screen width
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
<!-- HTML --> | |
<table> | |
<tr> | |
<td>Cell 1</td> | |
<td>Cell 2</td> | |
<td>Cell 3</td> | |
</tr> | |
<tr> | |
<td>Cell 4</td> | |
<td>Cell 5</td> | |
<td>Cell 6</td> | |
</tr> | |
</table> | |
<!-- CSS --> | |
/* Responsive tables class */ | |
.scrollable-table { | |
overflow-x:scroll; | |
} | |
<!-- JS --> | |
/** | |
* Responsive tables | |
* | |
*/ | |
if( $(window).width() > 500 ){ | |
//remove wrapper around tables | |
if ( $('table').parent().is( "div.scrollable-table" ) ) { | |
pTags.unwrap(); | |
} | |
console.log("Responsive tables disabled"); | |
} else { | |
//add table wrapper | |
$('table').wrap('<div class="scrollable-table"></div>'); | |
console.log("Responsive tables enabled"); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment