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.

Latest Current Affairs 2026 Online Exam Quiz for One day Exam Online Typing Test CCC Online Test Python Programming Tutorials Best Computer Training Institute in Prayagraj (Allahabad) Online MBA 2 years Online MCA Online BCA Best Website and Software Company in Allahabad