IE 8 prompts user on "slow" jQuery script

Posted by Jason on Stack Overflow See other posts from Stack Overflow or by Jason
Published on 2010-05-26T05:46:13Z Indexed on 2010/05/26 5:51 UTC
Read the original article Hit count: 226

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?

© Stack Overflow or respective owner

Related posts about JavaScript

Related posts about jQuery