I have just noticed that the order of elements returned by .get() seem
to have been reversed in 1.2.5 and 1.2.6.  Interestingly, each seems
to run in the expected order (from first element to last as
encountered in the document).  To demonstrate:

----------------------------------
<script src="http://jqueryjs.googlecode.com/files/jquery-1.2.5.js";></
script>
<span>1</span><span>2</span><span>3</span>
<script language=JavaScript><!--//
    $(function() {
        var arr=$("span").get();
        var txt=[];
        for(ai in arr) { txt.push(arr[ai].innerHTML); }
        alert("via get(): "+txt.join(","));
        $("span").each(function(i,o) { alert("via each #"+i
+".html="+o.innerHTML); });
    });
//--></script>
----------------------------------

Your first alert will show "via get(): 3,2,1".  Your next 3 alerts
will show 1,2,3 in order as the innerhtml.

This seems to come from around line 1133 of the jquery-1.2.5.js
(around the same line in 1.2.6), where the way the array is filled in
makeArray is:

----------------------
while( i )
  ret[--i] = array[i];
----------------------
(which obviously builds a backwards return array)

whereas in jquery-1.2.4.js line 1125 is code:

----------------------
for ( var i = 0, length = array.length; i < length; i++ )
  ret.push( array[ i ] );
-----------------------

It seems to me that the get() must return the elements in the document
specified order.  Even though this is not spelled out in the
specification it seems to be the only rational behavior.

If my assumption is correct then, the easiest way to fix is to insert:

------------
ret.reverse();
------------

at line 1141 of 1.2.6.js (or equivalent in future 1.2.7).



I have not found any posts on this or notes anywhere, but it is
possible I do not know every relavent area to check.  So don't beat me
up if this is known or desired behavior-- just tell me where I should
have looked.  Thanks!

Reply via email to