I have this code that works perfectly in latest Chrome, Firefox, Opera, but fails in IE9-10:
var div = document.querySelector('#wrap'),
para = document.querySelectorAll('#wrap p');
var paraArr = [].slice.call( para ).sort(function( a,b ) {
return a.textContent > b.textContent;
});
paraArr.forEach(function( p ) {
div.appendChild( p );
});
fiddle: http://jsfiddle.net/2nUMk/1/
Any ideas what the problem is? Is the sort implementation not the same in IE as in other browsers? Is even sort the problem here?
There is no need in div.innerHTML = ""; since it removes the sorted elements.
In the sorter function you may explicitly set the returned values:
var paraArr = [].slice.call(para).sort(function (a, b) {
return a.textContent > b.textContent ? 1 : -1;
});
DEMO: http://jsfiddle.net/2nUMk/3/
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With