[英]Changing element's HTML before it's inserted in the DOM
Is it possible to change an element's inner HTML before it is inserted in the DOM? 在将元素插入DOM之前,是否可以更改其内部HTML? I already tried doing this with MutationObserver but the problem is that you can see the element's HTML visually changing, is there a way to do this before DOM insertion altogether?
我已经尝试过使用MutationObserver进行此操作,但是问题是您可以看到元素的HTML发生了视觉变化,是否可以在完全插入DOM之前执行此操作?
var observer = new MutationObserver(function(mutations) {
mutations.forEach(function(mutation) {
mutation.addedNodes[0].innerHTML = "....";
});
});
// Notify me of everything!
var observerConfig = {
attributes: true,
childList: true,
characterData: true
};
var targetNode = document.querySelector("ul#myElement");
observer.observe(targetNode, observerConfig);
您可以尝试将整个正文显示为CSS display:none,更改所需的内容,然后再将其放回display:block
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.