Programming Examples
Create a paragraph element with the initial text Original Text.
Create a paragraph element with the initial text "Original Text".
(a) Create a button labeled "Change Text".
(b) In the function, change the text of the paragraph to “Text Changed!”.
(c) Ensure that the text is dynamically updated when the button is clicked.
Solution <p id="para">This is the original text.</p>
<button onclick="changeText()">Change Text</button>
Write within script Tag:
-----------------------------------
function changeText() {
document.getElementById("para").innerText = "Text Changed!";
}
▶ RUN Output/ Explanation: Creates a button labeled "Change Text".
When clicked, it calls the changeText() function.
The paragraph text changes to "Text Changed!" dynamically.