Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

IE 8 prompts user on "slow" jQuery script

I have a form with over 100 list items that I must reorder on submit. The following code works to reorder my list without any apparent problems in Firefox; however, IE prompts with the message "A script on this page is causing Internet Explorer to run slowly. If it continues to run, your computer may become unresponsive. Do you want to abort the script?" If the user clicks 'No', the script will work as expected.

var listitems = $(form).find('li').get();
listitems.sort(function(a, b) {
    var compA = $(a).attr('id');
    var compB = $(b).attr('id');
    return (compA - compB);
});

Any ideas on how to make this more efficient?

like image 544
Jason Avatar asked Feb 27 '23 23:02

Jason


1 Answers

I didn't try it with 100 items but it totally worked with 2.

listitems.sort(function(a, b) {
    return (a.id - b.id);
});
like image 74
Andy Gaskell Avatar answered Mar 12 '23 21:03

Andy Gaskell