[jQuery] Re: replaceWith returns the replaced element

2008-09-21 Thread tchvil
Richard, Thanks for your reply. It is neat but it leaks memory on IE. While the following not: $.fn.replaceWithAndReturnNew = function(html){ var div = document.createElement('div'); var replaced = this[0]; replaced.parentNode.replaceChild(d

[jQuery] Re: replaceWith returns the replaced element

2008-09-20 Thread tchvil
This one is slightly better altough not in jQuery style: $.fn.replaceWithAndReturnNew = function(html){ var elm = $(this)[0].cloneNode(false); $(this).after(elm).remove(); elm.innerHTML = html; return $(elm);}; On Sep 20, 9:31 am, tchvil <[EMAIL PROTECTED]> wrote

[jQuery] Re: replaceWith returns the replaced element

2008-09-20 Thread Richard D. Worth
$.fn.replaceWithAndReturnNew = function(htmls){ var replacer = $(htmls); $(this).replaceWith(replacer); return replacer; }; - Richard On Sat, Sep 20, 2008 at 3:31 AM, tchvil <[EMAIL PROTECTED]> wrote: > > Thanks a lot for your replies. > Ok, I guess there are good reasons to return the rep

[jQuery] Re: replaceWith returns the replaced element

2008-09-20 Thread tchvil
Thanks a lot for your replies. Ok, I guess there are good reasons to return the replaced object. Now my question becomes... is there a better jQuery way of doing this quite ugly thing: $.fn.replaceWithAndReturnNew = function(htmls){ var replaced = $(this)[0]; var div = document.c

[jQuery] Re: replaceWith returns the replaced element

2008-09-17 Thread Richard D. Worth
On Wed, Sep 17, 2008 at 4:58 PM, Karl Rudd <[EMAIL PROTECTED]> wrote: > > Err remove() is chainable. It doesn't "return a DOM element", it > "keeps hold" of the elements that it was called to remove from the > DOM. So it acts just like replaceWith(). > > There was a debate in the early stages of j

[jQuery] Re: replaceWith returns the replaced element

2008-09-17 Thread Ariel Flesler
Sorry, I missunderstood the initial (and subsequential) posts. The present behavior (return the initially matched element) is the correct one. That's what I'd expect and it matches the behavior of remove(), append(), etc. Don't file any bug report :) Thanks Richard for pinging me about this. --

[jQuery] Re: replaceWith returns the replaced element

2008-09-17 Thread Ariel Flesler
I think this is a bug, I'd expect replaceWith to return the old set, just like append/etc. Can you (tchvil) file a bug with a test case ? put it under core, assigned to me. Thanks -- Ariel Flesler http://flesler.blogspot.com/ On Sep 17, 8:04 am, "Richard D. Worth" <[EMAIL PROTECTED]> wrote: > O

[jQuery] Re: replaceWith returns the replaced element

2008-09-17 Thread Karl Rudd
Err remove() is chainable. It doesn't "return a DOM element", it "keeps hold" of the elements that it was called to remove from the DOM. So it acts just like replaceWith(). There was a debate in the early stages of jQuery about whether or not methods (not including the base $/jQuery function) tha

[jQuery] Re: replaceWith returns the replaced element

2008-09-17 Thread Richard D. Worth
On Wed, Sep 17, 2008 at 6:58 AM, Karl Rudd <[EMAIL PROTECTED]> wrote: > > Nah, it's not a bug. > > replaceWith( content ) Returns: jQuery > Replaces all matched elements with the specified HTML or DOM elements. > This returns the JQuery element that was just replaced, which has been > removed fro

[jQuery] Re: replaceWith returns the replaced element

2008-09-17 Thread Karl Rudd
Nah, it's not a bug. replaceWith( content ) Returns: jQuery Replaces all matched elements with the specified HTML or DOM elements. This returns the JQuery element that was just replaced, which has been removed from the DOM ( http://docs.jquery.com/Manipulation ) It's like doing a remove(), fol

[jQuery] Re: replaceWith returns the replaced element

2008-09-17 Thread Richard D. Worth
This sounds like a bug to me. Better raise it on the jQuery Dev list: http://groups.google.com/group/jquery-dev/ - Richard On Tue, Sep 16, 2008 at 4:58 AM, tchvil <[EMAIL PROTECTED]> wrote: > > Hi, > replaceWith returns the JQuery element that was just replaced. > > In the example below: > $( '