Javascript Add Text to Div
In this tutorial, we will learn how to add text to a div element dynamically using JavaScript. A div element is a container that can hold any HTML content, such as text, images, links, etc. Dynamically adding text means that we can change the content of the div without reloading the page or using a form. We will give two examples of how to do this. In the first example, we will use the textContent property of the div element to set or get the plain text inside it. In the second example, we will use the innerHTML property of the div element to set.
Thanks for your feedback!
Your contributions will help us to improve service.
Example 1 : Add Text to Div Javascript | textContent
In this example, we will learn how to add text to a `<div>` element using JavaScript's `textContent` property. The `textContent` property sets or returns the text content of a node and its descendants.
Output of Javascript Append Text to Div
Example 2 : Javascript Add Content to Div | innerHTML
In this example, we use innerHTML to add text to a div using JavaScript when the onclick button is triggered