JQuery issue in removing items in a dropdown

If you have a very large dropdown in an html page  Рsay a few thousand items, and you want to clear all of them, then using jQuery .empty() function is very slow. In most cases, it will hang the browser.  The fastest way is to use native javascript.

So instead of

$('#mydropdown').empty();

 

use

document.getElementById('mydropdown').items.length = 0;

 

Be the first to comment

Leave a Reply

Your email address will not be published.


*