Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Restore previous replaceWith behavior #28

Closed
nicofrand opened this issue Mar 8, 2013 · 5 comments

Comments

@nicofrand
Copy link

commented Mar 8, 2013

In jQuery < 1.9, replaceWith removed the current node if the content was null, undefined or an empty jQuery object.
Ex:

<div id="foo"></div>
$("#foo").replaceWith(function()
{
    return $(this).contents();
});

Expected Result :
DIV#foo is removed (ok in jQuery 1.8.3)

Actual result:
DIV#foo still exists.

How to restore the previous behavior :

$("#foo").remove(":empty").replaceWith(function()
{
    return $(this).contents();
});
@dmethvin

This comment has been minimized.

Copy link
Member

commented Mar 8, 2013

Can you provide a jsFiddle example? If I understand your snippet it sounds like $(this).contents() returns nothing which means it reduces to $("#foo").replaceWith([]) but an executable code sample would be less ambiguous.

@nicofrand

This comment has been minimized.

Copy link
Author

commented Mar 8, 2013

Sorry, I did not notice the HTML I wrote was not displayed.
Indeed, the contents method returns an empty object. Here is the jsFiddle example : http://jsfiddle.net/T5CjG/3/, please try with jQuery 1.8.3 and jQuery 1.9.1.
I hope this will be clear enough this time.

@dmethvin

This comment has been minimized.

Copy link
Member

commented Mar 11, 2013

Simpler and clearer test case: http://jsfiddle.net/dmethvin/T5CjG/4/

This seems more like a 1.9.1 bug and not something Migrate should handle. What do you think @gibson042 ?

@gibson042

This comment has been minimized.

Copy link
Member

commented Mar 11, 2013

This feels more like a 1.9 bug than a jquery-migrate one. The emptiness test in .replaceWith is too narrow; we should always call .domManip and then follow it with .remove() in case of no-op.

@gibson042

This comment has been minimized.

Copy link
Member

commented Mar 11, 2013

@gibson042 gibson042 closed this Mar 11, 2013
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
3 participants
You can’t perform that action at this time.