Sorting an array of objects by multiple properties
Hello,
I have a bunch of <article> elements on a page, some that have "data-order" attributes with values like "1", "6", etc. and some that don't.
I need to be able to move the <article> elements with this "data-order" attribute so that they appear in the order that's set in the attributes.
For example one of the article elements has this <article data-order="2">. That element in this example currently that appears right at the end all the other <articles>. What I want to do is move <article data-order="2"> so that it's 2nd within all the other articles.
For each circle I've tried using the "insertBefore" method to actually move the <article data-order> elements into the correct position, but there's an issue.
What I thought I could do is something like this:
- // $articles = $('article');
- // Re-order the articles from within the array
- // Remove all the articles from the DOM
- // Add all the articles into the DOM from the $articles array with the correct order
But I don't know how to re-order the circles within the array.
Any ideas?