javascript - Replace whole element rather than innerHTML? - Stack Overflow

I can do this:$('my-panel').innerHTML = '<p> New content <p>';But if t

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.

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.

Share Improve this question asked Aug 5, 2011 at 19:44 OliverOliver 11.6k18 gold badges75 silver badges127 bronze badges
Add a ment  | 

3 Answers 3

Reset to default 6

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

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

http://jsfiddle/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>'

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744352764a4570076.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信