HomeTutorsContact
JavaScript
How to replace inner html with JavaScript?
Gulshan Saini
May 29, 2020
1 min

In this quick tutorial I am going to show you how you can replace inner html contents of any element using property element.innerHTML

Tip: You can even use element.innerHTML to get markup of any element

Let’s start with following markup

Now, we are going to replace following paragraph element

with following h2 element

First, we need to get the reference of parent element, which is <div id="main"> in our case

Next, we can to set the inner html as follows

Output

Summary

  • The element.innerHTML can be used to get or set inner html of eny element

Tags

#dom-manipulation
Previous Article
How to create elements dynamically in Javascript?

Subscribe to our newsletter!

We'll send you the best of our blog just once a month. We promise.

Related Posts

How to iterate through NodeList using Javascript?
July 09, 2020
1 min
© 2020, All Rights Reserved.

Quick Links

Advertise with usContact Us

Social Media