简体   繁体   中英

jQuery sort not working in any IE browser

I'm about to pull my hair out, because of all the extra time spend on nursing IE -_-

Well, I have an unordered list of divs, which I'm trying to sort. This works perfectly in both Chrome and Firefox, but not IE.

The JS is fairly simple:

$('#VariantContainer > .ProductVariant').sort(function(a,b){
 return a.id > b.id
}).appendTo('#VariantContainer')

Check out this fiddle in IE: http://jsfiddle.net/PAJ3w/

Anyone got a clue why?

Thanks :)

BR Martin

Use number instead of boolean. For me this is the best variant (because it is obvious that we use numbers):

parseInt(a.id) - parseInt(b.id)
  jQuery(document).ready(function($){
  //Order variants
  $('#VariantContainer > .ProductVariant').sort(function(a,b){
        return a.id - b.id;
    }).appendTo('#VariantContainer');
  });

Boolean isn't the correct return type and doesn't account for equal values.

I think you're missing the semicolon on the line:

return a.id > b.id

Firefox and chrome can ignore those little things, but IE can't. It should be

return a.id > b.id;

You are declaring a function, therefore it follows all regular rules.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM