Return to Snippet

Revision: 8757
at October 6, 2008 09:25 by kouphax


Updated Code
(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);

Revision: 8756
at October 6, 2008 05:37 by kouphax


Initial Code
(function($){

    $.fn.sort = function() {
        return this.set($.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);

Initial URL


Initial Description
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).

Initial Title
inDOMOrder jQuery Plugin

Initial Tags
javascript, sort, jquery

Initial Language
JavaScript