how to get innerhtml of div in javascript code example

Example 1: change innerhtml

document.getElementById("p1").innerHTML = "New text!";

Example 2: .innerhtml

// .innerHTML method is used to change the html contents of a DOM object
document.getElementById("demo").innerHTML = "Paragraph changed!";

Example 3: javascript innerhtml

document.getElementById("example").innerHTML = "Paragraph changed!";

Example 4: js innerHTML

document.getElementById("Test").innerHTML = "<p style='color:red;'>Test</p>";

Example 5: how to change .innerhtml back

<div id="d"> old content </div> 
 
<script> 
    // Element stored in a variable for easy access 
    var div = document.getElementById("div"); 
 
    // Save the original content of the div 
    var old = div.innerHTML; 
 
    // Change the content of the div 
    div.innerHTML = "new content"; 
 
    // Reset the original content of the div 
    div.innerHTML = old; 
</script>

Tags:

Html Example