Replace whole element, not innerHTML?

I can do it:

$('my-panel').innerHTML = '<p> New content </p>';

But if there is a way to do something like

$('my-panel').wholeHTML = "<div id='my-panel'><p> New Content</p></div>";

I can not find any way. If I cannot do something like this, I will have to reorganize a whole bunch of things that will take a lot of time.

+5
source share
3 answers

How about outerHTMLa tag that includes the 'whole' tag:

$('my-panel').outerHTML = '<p> New content </p>';

http://jsfiddle.net/pimvdb/Sah2U/1/

+6
source

You use mootools, right? you can easily replace an element, i.e.:

Elements.from("<div id='my-panel'><p> New Content</p></div>").replaces($("my-panel"));
+2
source

you can always get parentNode tags and replace it with innerHTML

         $('my-panel').parentNode.innerHTML = '<p> New Content</p>'
+1
source

All Articles