How to replace innerHTML of a div using jQuery?

To replace innerHTML of a div in jQuery, use the html() or text() method. The html() method sets or returns the HTML content of an element, while text() sets or returns the text content without HTML formatting.

Using the html() Method

The html() method is the jQuery equivalent of JavaScript's innerHTML property. It can both get and set the HTML content of selected elements ?




   
   



This is Amit!

Using the text() Method

The text() method replaces content with plain text only, ignoring any HTML tags ?




   
   



This is original content!

Conclusion

Use html() when you need to insert HTML content with formatting, and text() when you want to insert plain text content safely without HTML interpretation.

Updated on: 2026-03-13T18:55:58+05:30

3K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements