Change Text in p tag JavaScript | Easy HTML example code

Find the element by id and use innerText attribute to Change Text in p tag in JavaScript. By this approach, you can change the text dynamically based on the conditions.

Example Change Text in p tag JavaScript

HTML example code change p tag text even its inside a div tag in js.

Output:

HTML Example Change Text in p tag JavaScript

Q: How to change the text inside <p> onClick ?

Answer: Same as above example with using a code inside the function. Function will Tigger on clicking a button.

Explanation

  • Here id_name is the id of the HTML tag to identify it.
  • innerHTML is used to change the text inside the selected HTML tag using the document.getElementById() method.
  • change_text() is function name.

Do comment if you have any doubts and suggestions on this topic.

Note: All JS Examples codes are tested on the Firefox browser and the Chrome browser.
OS: Windows 10
Code: HTML 5 Version


Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.