Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

replaceChild jQuery equivalent

I'm trying to replace current dom element with new element i made.

I implemented following line

$(this).parent().replaceChild(newElem,this);

But it gives error saying $(this).parent().replaceChild is not a function because replaceChild is not a jQuery function, what would be equivalent in jQuery?

like image 272
Rameez Avatar asked Sep 13 '13 04:09

Rameez


Video Answer


2 Answers

If what you want is to replace the inside:

$(this).empty().append('<p>replacement</p>')
like image 115
David Rz Ayala Avatar answered Oct 15 '22 13:10

David Rz Ayala


If you want to use pure jQuery you can use the replaceWith method

$(this).replaceWith(newElem);

you can refer this link :

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

like image 33
sana Avatar answered Oct 15 '22 13:10

sana