Microsoft Edge and Sorting with jQuery

I have the following code that works fine with Firefox and Chrome, but with Microsoft Edge (default settings) the list items are not sorted - they remain unordered. I am using MS Edge 20.10240.16384.0.

Has anyone seen this problem and found a solution? (id here is a ul container)

$( id + ' li' ).sort(function ( a, b ) {
    return parseFloat( $( a ).attr( "id" ).replace( 'page', '' ) )
         > parseFloat( $( b ).attr( "id" ).replace( 'page', '' ) );
}).appendTo( id + ' ul' );

JS script example: https://jsfiddle.net/c1d8caa5/2/

+4
source share
1 answer

This code uses its own method Array.prototype.sort, which is described in section 22.1.3.24 of the ECMAScript standard. This method takes a single comparefn argument:

comparefn undefined, , x y , x < y, , x = y , x > y. ( )

, , -1, 0, 1. , , , , , .

Microsoft Edge , ( ), Edge , , Edge .

Edge .

+3

Source: https://habr.com/ru/post/1623302/


All Articles