简体   繁体   English

替换整个元素而不是innerHTML?

[英]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: 那么outerHTML ,包括'整体'标签:

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

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

You use mootools, right? 你使用mootools,对吗? 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>'

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 innerHTML创建一个新元素,而不是替换目标元素的innerHTML - innerHTML creates a new element rather than replacing the innerHTML of the targeted element JQuery - 使用.innerHTML附加而不是替换内容? - JQuery - append rather than replace content using .innerHTML? 为什么 `innerHTML` 属性属于 JavaScript `Element` class 而不是 `HTMLElement`? - Why is the `innerHTML` property owned by the JavaScript `Element` class rather than `HTMLElement`? 这是引用整个 window 而不是 forEach 循环中的元素 - this is referencing the whole window rather than the element in forEach loop 滚动HTML元素而不是整个window对象的内容 - Scrolling the content of an HTML element, rather than the whole window object 定位文档而不是其中的元素时,如何用.on()替换.live() - How to replace .live() with .on() when targeting the document rather than an element within 数据列表搜索innerHTML而不是值? - Datalist search innerHTML rather than value? 清空元素的innerHTML将清空整个页面 - Emptying the innerHTML of an element empties the whole page 在Aurelia中用模板本身替换自定义元素(而不是将其包含在自定义元素中)? - Replace Custom Element with template itself (rather than including it inside the custom element) in Aurelia? 由每个节点限制,而不是整个查询 - Limit by each node, rather than whole query
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM