Sometimes, we want to replace or change the heading text inside h3 with JavaScript.
In this article, we’ll look at how to replace or change the heading text inside h3 with JavaScript.
How to replace or change the heading text inside h3 with JavaScript?
To replace or change the heading text inside h3 with JavaScript, we set the innerText
property.
For instance, we write
<h3 id="myHeader"></h3>
to add a h3 element.
Then we write
const myHeader = document.querySelector("#myHeader");
myHeader.innerText = "hello";
to select it with querySelector
.
Then we change its text content by setting the innerText
property.
Conclusion
To replace or change the heading text inside h3 with JavaScript, we set the innerText
property.