Quantcast
Channel: Internet Explorer Web Development forum
Viewing all articles
Browse latest Browse all 3527

The Superiority of Microsoft Internet Explorer - JavaScript Sort - function

$
0
0

Since Firefox is still "avoiding" support for HTML5 Standard "innerText" property - here is a version usingtextContent
where you can test the sort ability and stability on each UA you may currently have...

Fiddle: http://jsfiddle.net/sxxzhLxd/1/

<!DOCTYPE html><html><head><style>
div div { padding: 1px 1em };</style></head><body><div id=test><div style="background-color:yellow">B</div><div style="background-color:yellow">D</div><div style="background-color:yellow">A</div><div style="background-color:yellow">C</div><div style="background-color:yellow">E</div><div style="background-color:orange">B</div><div style="background-color:orange">D</div><div style="background-color:orange">A</div><div style="background-color:orange">C</div><div style="background-color:orange">E</div><div style="background-color:red">B</div><div style="background-color:red">D</div><div style="background-color:red">A</div><div style="background-color:red">C</div><div style="background-color:red">E</div></div><input type=button value="Sort" onclick="dosort()"><script>

function dosort() {
    var i = 0,
        elements = [].slice.call(test.children).
        sort(function (a, b) {
            if (a.textContent < b.textContent) return -1;
        });
    while (elements[i])
    test.appendChild(elements[i++]);
}</script></body></html>

Have fun!


Viewing all articles
Browse latest Browse all 3527

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>