Note that there are some explanatory texts on larger screens.

plurals
  1. POWhy does this javascript run so slow in IE when all it does is modify a select list?
    text
    copied!<p>I'm working on having a multi-select list where you can have items selected and then click an "Up" or "Down" button that will allow you to reorder those items within the list.</p> <p>I've got a simple self-contained example:</p> <pre><code>&lt;html&gt; &lt;head&gt; &lt;title&gt;Example&lt;/title&gt; &lt;script src="https://www.google.com/jsapi"&gt;&lt;/script&gt; &lt;script&gt; google.load('jquery', '1.4.1'); &lt;/script&gt; &lt;/head&gt; &lt;body&gt; &lt;select id="selectedDataPoints" multiple="multiple"&gt; &lt;option&gt;Pig&lt;/option&gt; &lt;option&gt;Duck&lt;/option&gt; &lt;option&gt;Dog&lt;/option&gt; &lt;option&gt;Zebra&lt;/option&gt; &lt;option&gt;Snake&lt;/option&gt; &lt;option&gt;Giraffe&lt;/option&gt; &lt;option&gt;Cow&lt;/option&gt; &lt;/select&gt; &lt;input type="button" id="btnReorderUp" value="Up" /&gt; &lt;input type="button" id="btnReorderDown" value="Down" /&gt; &lt;/body&gt; &lt;/html&gt; &lt;script type="text/javascript"&gt; var DataPointSelector = (function() { var $selectedList = $('#selectedDataPoints'); $('#btnReorderUp').click(function(e) { moveUp(); e.preventDefault(); }); $('#btnReorderDown').click(function(e) { moveDown(); e.preventDefault(); }); function moveUp() { var select = $selectedList[0]; for (var i = 1, n = select.options.length; i &lt; n; i++) if (select.options[i].selected &amp;&amp; !select.options[i - 1].selected) select.insertBefore(select.options[i], select.options[i - 1]); } function moveDown() { var select = $selectedList[0]; for (var i = select.options.length - 1; i &gt; 0; i--) if (select.options[i].selected &amp;&amp; !select.options[i + 1].selected) select.insertBefore(select.options[i + 1], select.options[i]); } } ()); &lt;/script&gt; </code></pre> <p>However, the Up/Down button takes literally 3-8 seconds to take effect in IE7/8. The first click will sometimes be fast but after that it takes a very long time for the select list to update with the new positions (especially if you have a couple items selected).</p> <p>This problem is not present in Chrome/FF. I wouldn't have thought this simple reordering would be so intensive!</p> <p>Does anyone have any information that could be used to help me speed the moveUp/moveDown functions?!</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload