All TalkersCode Topics

Follow TalkersCode On Social Media

jQuery Set innerHTML

Last Updated : Jan 1, 2023

jQuery Set innerHTML

In this article we will show you the solution of jQuery set innerHTML, in jquery we can’t use innerHTML because they provided another methods of text() and html() replaced this. So here we are going to use html() method for achieve the result.

The html() method also having same behavior of innerHTML so we can append any string or text on any element in html document.

Step By Step Guide On jQuery Set innerHTML :-

In html we defined p element with id attribute and button ‘Set’ with id ‘st’.

In script block we defined ready() method which is automatically starts loading code of within this function when this program opened on browser.

There we appended click() method on button and within this we specified p tag then which is appends with html() method for sets some text on paragraph tag.

<!DOCTYPE html>
        <title>Set innnerHTML</title>
        <script src=""></script>
                    $("#pele").html("Hi Everyone");
        <p id="pele"></p>
        <button id="st">Set</button>
  1. <!DOCTYPE html> tag which is instruct the web browser about what version of HTML file written in and it’s not have any ending tag.
  2. The<html> tag is used to indicate the beginning of HTML document.
  3. As above shown <head> tag is contain information about webpage and external file links are declared here. <title> tag is used for set the webpage title.
  4. Here we imported open source jquery library support file which is needed for coding using jquery in program.
  5. Both <head> and <title> tags having their pair end tag, so we need to close the ending tags respectively. If you’re not closed anyone of ending tag properly that is also affect the webpage result.
  6. <body> tag is beginning of main coding part because it contain coding of entire website blocks and elements described here.
  7. We defined paragraph element with id ‘pele’ for inserts text on it and button ‘Set’ with id ‘st’ for proceeds process when user clicks on it.
  8. In script we defined ready() method within that we appended click() method on button ‘Set’ by id attribute ‘st’. There we specified p element by id attribute ‘pele’ and which is appends with html() method with string ‘Hi Everyone’.
  9. Both </body>,</html> tags closed respectively. </body> tag indicates the end of body, Then </html> tag indicates the end of HTML document.

Conclusion :-

In conclusion now we are able to know how to set text on element instead of innerHTML in jquery.

Before execution of program we needs to confirm internet connection because then only that jquery file will supports defined jquery codes without error.

When we executes program on browser we can see button ‘Set’ now user needs to clicks on it then we can see added text ‘Hi Everyone’ on paragraph element.

If you wants to add any other text or string just modify it accordingly and you can also use text() method instead of html().

I hope this article on jQuery set innerHTML helps you and the steps and method mentioned above are easy to follow and implement.

Latest Tutorials