[英].textContent not working on a cloned node
I'm trying to clone a DOM element and then replace the text inside of it. 我正在尝试克隆DOM元素,然后替换其中的文本。 Here is a very simple example.
这是一个非常简单的例子。
https://codepen.io/anon/pen/rmZbPR https://codepen.io/anon/pen/rmZbPR
The issue is that the cloning appears to prevent .textContent (or .innerHTML) from working. 问题是克隆似乎阻止了.textContent(或.innerHTML)正常工作。 I get the following error...
我收到以下错误...
Uncaught TypeError: pCloned.textContent is not a function
Any pointers would be much appreciated. 任何指针将不胜感激。
var p = document.getElementById('para'); var pCloned = p.cloneNode(true); // Remove this to see that the clone works correctly pCloned.textContent('This is a cloned paragraph'); document.getElementById('list').appendChild(pCloned);
<p id="para">This is a paragraph</p> <div id="list"></div>
textContent
is not a function, but a simple get/set string property. textContent
不是函数,而是简单的get / set字符串属性。 Correct it to this: 对此进行更正:
pCloned.textContent = 'This is a cloned paragraph';
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.