Categories
JavaScript Answers

How to append text to a div with JavaScript?

Spread the love

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.

By John Au-Yeung

Web developer specializing in React, Vue, and front end development.

Leave a Reply

Your email address will not be published. Required fields are marked *