Bug Tracker

Opened 14 years ago

Closed 13 years ago

#4604 closed bug (duplicate)

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:


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.

Change History (5)

comment:1 Changed 14 years ago by dmethvin

Can you attach a simple test case?

comment:2 Changed 14 years ago by brandon

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.

comment:3 Changed 13 years ago by jayfresh

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);

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();
    if (s.size())

comment:4 Changed 13 years ago by jayfresh

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.


comment:5 Changed 13 years ago by john

Resolution: duplicate
Status: reopenedclosed

Duplicate of #2697.

Note: See TracTickets for help on using tickets.