Answers for "javascript how to sort nodes from dom"

1

javascript how to sort nodes from dom

var list = document.getElementById('list');

[...list.children]
  .sort( (a, b) => a.getAttribute('data-date') - b.getAttribute('data-date'))
  .forEach( node => list.appendChild(node));
Posted by: Guest on July-24-2021

Code answers related to "javascript how to sort nodes from dom"

Code answers related to "Javascript"

Browse Popular Code Answers by Language