Hi!

In a recent project I often needed to copy a jQuery object to save a 
subquery without losing the original query. As far as I can see there is 
no "official way" to do this so I came up with a small extension function:

$.fn.newQuery = function()
{
     var c = $();
     c.cur = $.merge([], this.cur);
     return c;
}

Usage example:

// I need these queries very often so I want to save the results
// within a variable
$fields = $('input.dynamic, textarea.dynamic, select.dynamic');
$requiredFields = $fields.newQuery().filter('.required');

I'm pretty sure that I will need this function in almost every future 
project when I use jQuery. Is there an official way to do this that I 
missed?

What I would really like to see in the standard library is that jQuery 
objects can be passed to the $() function to obtain a copy:

var $a = $('some.query');
var $b = $($a);

$b.filter('some.criteria'); // Does not affect $a

What do you think about that?

-- Ferdinand



_______________________________________________
jQuery mailing list
discuss@jquery.com
http://jquery.com/discuss/

Reply via email to