简体   繁体   中英

Replace whole element rather than innerHTML?

I can do this:

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

But if there any way of doing something like

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

I can't find any way. If I can't do something like this, I'll have to refactor a whole bunch of stuff, which would be time consuming.

What about outerHTML , which includes the 'whole' tag:

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

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

You use mootools, right? you could easily replace the element, ie:

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

你总是可以获得标签parentNode并替换他的innerHTML

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM