I am working on a list with several choices in which you can select items, and then click the Up or Down button, which will allow you to reorder these items in the list.
I have a simple standalone example:
<html> <head> <title>Example</title> <script src="https://www.google.com/jsapi"></script> <script> google.load('jquery', '1.4.1'); </script> </head> <body> <select id="selectedDataPoints" multiple="multiple"> <option>Pig</option> <option>Duck</option> <option>Dog</option> <option>Zebra</option> <option>Snake</option> <option>Giraffe</option> <option>Cow</option> </select> <input type="button" id="btnReorderUp" value="Up" /> <input type="button" id="btnReorderDown" value="Down" /> </body> </html> <script type="text/javascript"> 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 < n; i++) if (select.options[i].selected && !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 > 0; i--) if (select.options[i].selected && !select.options[i + 1].selected) select.insertBefore(select.options[i + 1], select.options[i]); } } ()); </script>
However, the Up / Down button takes literally 3-8 seconds to take effect in IE7 / 8. The first click will sometimes be quick, but after that, the selection list needs to be updated with new positions (especially if you have a couple of elements).
This issue is missing in Chrome / FF. I would not have thought that this simple reordering would be so intense!
Does anyone have any info that could help me speed up the moveUp / moveDown functions ?!
performance javascript jquery selectlist
Markus
source share