DEV Community


Discussion on: Sorting HTML elements with Flexbox and JavaScript

kevinhch profile image

Pretty good code, but you can use the flex-direction: column-reverse; and some JS to get the same result

nijeesh4all profile image
Nijeesh Joshy Author • Edited

Thats a really good point. we can use it to change the direction of the elements we cannot achieve sorting with that approach,
you wont get it sorted properly if the the elements are mixed.

say elements are in the order 1,2,3,4,9,5,10 so if you sorted it with flex-direction: column-reverse; what you will get is 10, 5, 9, 4, 3, 2, 1 its not what we are looking for.