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:
DEMO: http://jsfiddle.net/2nUMk/3/