replaceChild jQuery等价

Ram*_*eez 7 javascript jquery jquery-plugins

我正在尝试用我制作的新元素替换当前的dom元素.

我实施了以下一行

$(this).parent().replaceChild(newElem,this);
Run Code Online (Sandbox Code Playgroud)

但它给出了错误说$(this).parent().replaceChild is not a function因为replaceChild不是jQuery函数,jQuery中的等价物是什么?

Dav*_*ala 21

如果你想要的是更换内部:

$(this).empty().append('<div></div>')
Run Code Online (Sandbox Code Playgroud)


小智 11

如果要使用纯jQuery,可以使用replaceWith方法

$(this).replaceWith(newElem);
Run Code Online (Sandbox Code Playgroud)

你可以参考这个链接:

http://api.jquery.com/replaceWith/