I'm trying to sort an li
elements and get an unexpacted result
I need to sort it three times to get it correctly,
where have I mistaken?
javascript
var sort_by_name = function(a, b) {
return a.innerHTML.toLowerCase() > b.innerHTML.toLowerCase();
}
$this = $("ol#table1");
var list = $this.children();
list.sort(sort_by_name);
console.log(list);
$this.html(list);
HTML
<ol id="table1" style="display: block; ">
<li class="menu__run">I</li>
<li class="menu__run">IXX</li>
<li class="menu__run">I</li>
<li class="menu__run">I</li>
<li class="menu__run">I</li>
<li class="menu__run">I</li>
<li class="menu__run">I</li>
<li class="menu__run">I</li>
<li class="menu__run">IXX</li>
<li class="menu__run">I</li>
<li class="menu__run">I</li>
<li class="menu__run">I</li>
<li class="menu__run">I</li>
<li class="menu__run">I</li>
<li class="menu__test">st</li>
<li class="menu__test">st</li>
<li class="menu__test">st</li>
</ol>
fiddle example
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…