Ferdinand -
I just added in object cloning with the constructor function, you can now do:
var div = $("div")
$(div).find("span")
and have the original 'div' still contain what it's supposed to.
--John
On 8/28/06, Ferdinand Beyer <[EMAIL PROTECTED]> wrote:
> Hi!
>
> In a recent project I often needed to copy a jQuery object to perform a
> subquery without losing the original object. 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?
_______________________________________________
jQuery mailing list
[email protected]
http://jquery.com/discuss/