Skip to content

How to sort a list of DOM elements in an HTML document

Lloyd Brookes edited this page Oct 26, 2019 · 8 revisions
function sortChildren (el, sortOptions) {
  sortArray([...el.children], sortOptions).map(child => el.appendChild(child))
}
sortChildren($('ul'), {
  by: 'textContent',
  order: 'desc'
})

Clone this wiki locally