私はnodeValueを使ってテキスト内のテキストをelement.firstChild.nodeValue = text
のように変更できますが、同じことをするにはsetAttributeを使用できますか?setAttributeを使用してテキストノード内のテキストを変更できますか?
HTML:
<p id="description">Some text here.</p>
JS:
var description = document.getElementById("description");
description.setAttribute(nodeValue, text);
それは動作しません。 "nodeValue"は要素の属性ではないことを意味しますか?あなたがあなたの代わりに.textContent
を使用することができますので、ここではなくノード属性をノード内容を設定したい