Sometimes, we want to append text to a div with JavaScript.
In this article, we’ll look at how to append text to a div with JavaScript.
How to append text to a div with JavaScript?
To append text to a div with JavaScript, we append the text to the innerHTML
string.
For instance, we write
const div = document.getElementById("divID");
div.innerHTML += "Extra stuff";
to select the div with getElementById
.
Then we append the new text by concatenating it to the innerHTML
string.
Conclusion
To append text to a div with JavaScript, we append the text to the innerHTML
string.