Skip to content

Instantly share code, notes, and snippets.

@paoga87
Last active January 20, 2017 13:24
Show Gist options
  • Save paoga87/a6a26fa82901603cec00f20986e40557 to your computer and use it in GitHub Desktop.
Save paoga87/a6a26fa82901603cec00f20986e40557 to your computer and use it in GitHub Desktop.
After having a list of buttons with event dates/names, with the date formatted as string, I decided to re-format the date (after fetching the elements via MySQL/PHP) like this: dd/mm/yyyy, and added each to the individual buttons as IDs. Then do the sorting straight from jQuery. (Querying the MySQL with PHP back-end was not an option because the…
// Functionality to sort the event buttons by date using jQuery
var $results = $('.mainDivClass'); //This could be an id as well
var $itemBtn = $results.children('.individualItemClass'); //This could be an id as well
$itemBtn.detach();
$itemBtn.sort(function(a,b){
return a.id > b.id;
});
$itemBtn.appendTo($results);
// -- End of Functionality to sort the event buttons by date --//
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment