![](/img/trans.png)
[英]innerHTML creates a new element rather than replacing the innerHTML of the targeted element
[英]Replace whole element rather than innerHTML?
我可以做这个:
$('my-panel').innerHTML = '<p> New content </p>';
但是,如果有任何方式做某事
$('my-panel').wholeHTML = "<div id='my-panel'><p> New Content</p></div>";
我找不到任何办法。 如果我不能做这样的事情,我将不得不重构一大堆东西,这将耗费时间。
那么outerHTML
,包括'整体'标签:
$('my-panel').outerHTML = '<p> New content </p>';
你使用mootools,对吗? 你可以轻松地替换元素,即:
Elements.from("<div id='my-panel'><p> New Content</p></div>").replaces($("my-panel"));
你总是可以获得标签parentNode并替换他的innerHTML
$('my-panel').parentNode.innerHTML = '<p> New Content</p>'
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.