Sort by from big to small
AppendChild:
Assuming that child Node B is already in parent a, then A.appendchild (b) is: 1. First remove child Node B from parent a, 2. Then add child node B to a, and put it at the very end.
<body>
<button id= "BT1" > Submit </button>
<ul id= "UL1" >
<li>32</li>
<li>243</li>
<li>43</li>
<li>24</li>
<li id= "T" >2 </li>
<li>84</li>
<li>84</li>
<li>25</li>
</ Ul>
</body>
<script>
window.onload=function () {
var Oul1=document.getelementbyid (' Ul1 ');
var Obt=document.getelementbyid (' bt1 ');
Obt.onclick=function () {
var oli=document.getelementsbytagname (' Li ');
var arr=[];
Put <li> tags in an empty arr array for
(Var i=0;i<oli.length;i++) {
arr[i]=oli[i];
}
Sort, each element in the array is a <li>, so you want to use innerHTML
arr.sort (function (li1,li2) {
var n1=parseint ( li1.innerhtml);
var n2=parseint (li2.innerhtml);
return n1-n2;
})
Sort by AppendChild for
(var i=0;i<arr.length;i++) {
oul1.appendchild (arr[i]);
}} </script>
The above is small series for everyone to bring the JS using AppendChild to the label to sort the implementation of the whole content, I hope that we support cloud Habitat Community ~