xxxxxxxxxx
var out = document.getElementById("out");
var res = out.innerHTML;
res = "foo";
xxxxxxxxxx
// .innerHTML method is used to change the html contents of a DOM object
document.getElementById("demo").innerHTML = "Paragraph changed!";
xxxxxxxxxx
var myInnerHtml = document.getElementById("forloop").innerHTML;
xxxxxxxxxx
<p id="demo"></p>
<p id="myList">This is my text</p>
// first way of accessing element
document.getElementById("demo").innerHTML = "I have changed!";
// second way of accessing element
var element=document.getElementById("demo");
element.innerHTML = "I have changed!";
// get text of id myList
let html = document.getElementById("myList").innerHTML;
xxxxxxxxxx
document.getElementById("Test").innerHTML = "<p style='color:red;'>Test</p>";
xxxxxxxxxx
// Try to use `textContent` instead of innerHTML as innerHTML can be hacked.
document.getElementById("myHeader").textContent = "Heading"
xxxxxxxxxx
// Get the element you want to modify
const element = document.getElementById('myElement');
// Set the inner HTML content
element.innerHTML = 'New HTML content';
xxxxxxxxxx
// Get the element on which we want to set the innerHTML
const element = document.getElementById('elementId');
// Set the innerHTML of the element
element.innerHTML = 'New innerHTML value';