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!";
        }
Output

Creates a button labeled "Change Text".

When clicked, it calls the changeText() function.

The paragraph text changes to "Text Changed!" dynamically.

Online Exam Quiz for One day Exam Online Typing Test CCC Online Test 2026 Best Computer Training Institute in Prayagraj (Allahabad) Best Java Training Institute in Prayagraj (Allahabad) Best Python Training Institute in Prayagraj (Allahabad) O Level Online Test in Hindi Best Website and Software Company in Allahabad