/ Published in: JavaScript
jQuery Plugin for returning selected DOM Nodes in DOM order. e.g. $('img.L,img.Y') will not be guaranteed DOM order (usually all the L's then all the Y's).
Currently only works with IE and FF (that's all I needed).
Currently only works with IE and FF (that's all I needed).
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
(function($){ $.fn.sort = function() { return this.pushStack($.makeArray( [].sort.apply(this, arguments))); }; function DOMOrderComparator(a,b){ if($.browser.msie){ return a.sourceIndex - b.sourceIndex; }else if($.browser.mozilla){ return 3 - (a.compareDocumentPosition(b) & 6); } } $.fn.inDOMOrder = function(){ return this.sort(DOMOrderComparator) } })(jQuery);