Javascript to change Text
Description :
Javascript can be used to change the text of a paragraph as well. Once we are able to get access to a DOM element that takes text, we can change the innerText to whatever we want using Javascript.
Example :
The following paragraph is displayed using the following code:
<p id="para-1"> Hello! </p>
Hello!
And we have a button:
When we click the button, our JS catches the click event from the button and changes the innerText of the paragraph with the "para-1" id. The code for this can be found below:
document.getElementById("para-1").innerText = "Tra La La!";