Skip to content

Instantly share code, notes, and snippets.

@goodyis
Created October 9, 2017 20:42
Show Gist options
  • Save goodyis/a6fa9ff5c4809de50d84f2f3ea29a3e3 to your computer and use it in GitHub Desktop.
Save goodyis/a6fa9ff5c4809de50d84f2f3ea29a3e3 to your computer and use it in GitHub Desktop.
Alphabetically sorting table by rows, via td value using jQuery
$( "div.protected-downloads" ).each( function ( index ) {
$dType = $( this ).data( 'type' );
$combined = $dType + "_table";
$( this ).find(' table tbody' ).addClass( $combined );
$mylist = $( '.' + $combined );
$listitems = $mylist.find( 'tr:not(".hidden")' );
$listitems.sort( function( a, b ) {
return $( a ).text().toUpperCase().localeCompare( $( b ).text().toUpperCase() );
})
$.each( $listitems, function( idx, itm ) { $mylist.append( itm ); } );
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment