CSS
- 3 ответа
- 0 вопросов
3
Вклад в тег
var list = document.querySelector('.sort-list');
var sortElem = list.getElementsByTagName('li');
var nEntryArray = Array.prototype.slice.call(sortElem, 0);
nEntryArray.sort(function(a, b) {
return a.firstChild.nodeValue - b.firstChild.nodeValue
})
while (list.lastChild) {
list.removeChild(list.lastChild);
}
var sortList = document.createDocumentFragment();
for (i = 0, l = nEntryArray.length; i < l; i++) {
sortList.appendChild(nEntryArray[i]);
}
list.appendChild(sortList);
<ul class="sort-list">
<li class="l1">31</li>
<li class="l2">11</li>
<li class="l3">16</li>
</ul>