Skip to main content

Bug Tracker

Side navigation

#4604 closed bug (duplicate)

Opened April 28, 2009 10:44PM UTC

Closed December 05, 2009 08:23PM UTC

replaceWith is not removing old content before adding new content

Reported by: soichih Owned by:
Priority: minor Milestone: 1.4
Component: core Version: 1.3.2
Keywords: replaceWith Cc:
Blocked by: Blocking:
Description

I have multiple select boxes under a div, and when I use replaceWith to replace the entire div containing 2 select boxes, the replaceWith will first try to add new div before removing the old div.

This causes all 4 select boxes to co-exist in the DOM thus causing event handling mechanism to malfunction (in Firefox). The work around I have found is to do following

node.empty(); node.replaceWith(res.responseText);

It would save a lot of time for someone if this behavior could be changed in the replaceWith function.

Attachments (0)
Change History (5)

Changed May 01, 2009 01:35AM UTC by dmethvin comment:1

Can you attach a simple test case?

Changed May 06, 2009 04:03PM UTC by brandon comment:2

need: ReviewTest Case
resolution: → invalid
status: newclosed

Please attach a complete test case. Are you using clone to create the second div? Cloning form elements has issues cross-browser.

Changed October 28, 2009 04:41PM UTC by jayfresh comment:3

resolution: invalid
status: closedreopened

I don't have a way to show you a simple test case right now, but I had this problem too - I am testing in IE6 and FF3.5 and it's only a problem in IE.

I am replacing an input with a constructed drop-down - this is the code ($row.val is pointing at the input):

var $select = this.makeSelect(values);
$row.val.replaceWith($select);

I have found that if I replace 'replaceWith' with the function suggested in #2697, the problem goes away. Here is the code for that function:

$.fn.replaceWith = function(value) {
    return this.each(function() {
    var e = $(this);
    var s = e.next();
    var p = e.parent();
    e.remove();
    if (s.size())
        s.before(value);
    else
        p.append(value);
    });
};

Changed October 28, 2009 04:43PM UTC by jayfresh comment:4

Worth also mentioning that the event handlers on $row didn't fire after a change event on $row.val. With the replacement code in place, they fired.

J.

Changed December 05, 2009 08:23PM UTC by john comment:5

resolution: → duplicate
status: reopenedclosed

Duplicate of #2697.