要更改 html 标签的内容,请使用 innerHTML 属性:
var h4 = document.getElementsByClassName("author_name")[0],
target = h4.childNodes[0];
target.innerHTML = "About the author";
这是代码:
document.getElementById("id-of-element").innerHTML = "new text";
<!DOCTYPE html>
<html>
<body>
<p id="id-of-element">This text will be replaced</p>
</body>
</html>
这非常简单,您只需使用innerText或textcontent,如下例所示
//textConent Method
const authorName = document.querySelectorAll('author_name').textContent="Text Here"
//innerText Method
const authorName = document.querySelectorAll('author_name').innerText="Text Here"