Here's a kind of 'DOM order sort plugin' I just made adapting code from the 'getElementsByTagNames' function by Peter-Paul Koch (http:// www.quirksmode.org/dom/getElementsByTagNames.html).
I haven't tested it anywhere besides FF3. Just use it as: $('div,span').sort() (function($){ $.fn.sort = function(){ var arr = $.makeArray(this), firstNode = this[0]; if (firstNode.sourceIndex) { arr.sort(function (a,b) { return a.sourceIndex - b.sourceIndex; }); } else if (firstNode.compareDocumentPosition) { arr.sort(function (a,b) { return 3 - (a.compareDocumentPosition(b) & 6); }); }; return $(arr); }; })(jQuery); I'd appreciate some feedback if this works :] - ricardo On Dec 1, 11:55 pm, brian <[EMAIL PROTECTED]> wrote: > FWIW, same problem using > $('form#myform').find('*').filter('input,select,textarea'); > > It seems that jQuery creates a new collection but iterates through for each > selector in filter(), gathering matches from the source, rather than running > through the source and comparing each element with each selector. > > Did that make sense? > > On Mon, Dec 1, 2008 at 5:15 PM, Hector Virgen <[EMAIL PROTECTED]> wrote: > > Is there a way to make $.fn.find() return the elements in the order they > > appear in the dom instead of grouped by selector? > > For example, let's say I have a form and I want to get the first form > > control, whether it's an input, select, or textarea. Here's some basic HTML: > > > <form id="#myform"> > > <select>// ... //</select> > > <input type="text" /> > > </form> > > > I thought I could do this, but it's returning the wrong element: > > > var form_controls = $('form#myform').find('input, select, textarea'); > > console.log('first: ' + form_controls[0].tagName); // <-- first: INPUT, > > should be SELECT > > > Is there a way to get the desired effect with jQuery? Thanks! > > > -Hector