Discuss / JavaScript / Answer

Answer

Topic source

NotFatCat

#1 Created at ... [Delete] [Delete and Lock User]
// sort list:
var
        arr, i,
        t = document.getElementById('test-list');
    arr=[];
    for(i=0;i<t.children.length;i++){
        arr.push(t.children[i].innerText);
    }
  arr.sort();
    for(i=0;i<arr.length;i++){
     var test = document.createElement('li');
     test.class='lang';
     test.innerText=arr[i];
     t.removeChild(t.children[0]);
     t.appendChild(test);
  }
alert(arr.toString());

  • 1

Reply