[jQuery] Re: how to add elements to a jQuery object without copying it

2008-09-23 Thread Michael Geary
> From: ~flow > > the second suggestion does work; however, the > pre-incrementing index has to be written as a > post-incrementing index, like this: > > var t = $( '.foo' ); > var s = t; > t[ t.length++ ] = $Q( '.bar' )[ 0 ]; // should now like > like $ ( '.foo,.bar' ) > assert( s ==

[jQuery] Re: how to add elements to a jQuery object without copying it

2008-09-23 Thread ~flow
oops, little typo---got to use `$Q` instead of `$` in my project. wrote an extension method: jQuery.fn.push = function( selector_or_nodes ) { // Given a selector or a jQuery object, append all of the nodes to the current jQuery object. var nodes = $is_string( selector_or_nodes )? $Q( selecto

[jQuery] Re: how to add elements to a jQuery object without copying it

2008-09-23 Thread ~flow
thanx a lot, i think i’ve got it. actually, the first part of your answer does not work for me---with `add`, a new collection is returned. this breaks object identity (hence, you cannot keep a reference from another variable to the jQuery object in question once you've done `add`). the second su

[jQuery] Re: how to add elements to a jQuery object without copying it

2008-09-23 Thread ricardobeat
a jQuery object is not a real array. The add() function does what you want: var foobar = $('.foo').add('.bar'); If you want to add elements manually use: var $foo = $('.foo'); $foo[ ++$foo.length ] = $('.bar')[0]; - ricardo On Sep 23, 4:35 pm, "~flow" <[EMAIL PROTECTED]> wrote: > i seem to re