[英]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.