javascript - How to repeatedly sort element in div without losing clickability? -
example of need:
var interval = 100; $(function(){ $('#container').children().click(function(e){ alert($(e.target).text()+" clicked"); }); setinterval(function(){ $('#container').children().sort(function(a,b){ if($(a).text() > $(b).text()) return 1; if($(a).text() < $(b).text()) return -1; return 0; }).appendto('#container'); },interval); })
if change interval 10000 works fine.
but need interval 100 or lower.
modified fiddle compare. please check http://jsfiddle.net/bbgmb/4/
var interval = 100; $(function(){ $('#container').children().click(function(e){ alert($(e.target).text()+" clicked"); }); setinterval(function(){ var origc = $('#container').children(); var newc = $.extend([], origc); newc.sort(function(a,b) { if($(a).text() > $(b).text()) return 1; if($(a).text() < $(b).text()) return -1; return 0; }); (var i=0; < origc.length; i++) { if (origc[i] !== newc[i]) { newc.appendto('#container'); break; } } },interval); })
Comments
Post a Comment