开发者

Replace whole element rather than innerHTML?

开发者 https://www.devze.com 2023-03-26 10:27 出处:网络
I can do this: $(\'my-panel\').innerHTML = \'<p> New content </p>\'; But if there any way of doing something like

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 refacto开发者_如何转开发r 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, i.e.:

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


you can always get the tags parentNode and replace his innerHTML

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

精彩评论

暂无评论...
验证码 换一张
取 消