Javascript - innerHTML

The innerHTML property can be used to write the dynamic html on the html document.

It is used mostly in the web pages to generate the dynamic html such as registration form, comment form, links etc.

Example of innerHTML property

In this example, we are going to create the html form when user clicks on the button.

In this example, we are dynamically writing the html form inside the div name having the id mylocation. We are identifing this position by calling the document.getElementById() method.

"; document.getElementById('mylocation').innerHTML=data; }
Test it Now

Output of the above example

Show/Hide Comment Form Example using innerHTML

"; if(flag){ document.getElementById("mylocation").innerHTML=cform; flag=false; }else{ document.getElementById("mylocation").innerHTML=""; flag=true; } }

Output of the above example

Hot Tutorials

Contact US

JS innerHTML property