// .innerHTML method is used to change the html contents of a DOM object
document.getElementById("demo").innerHTML = "Paragraph changed!";
// Try to use `textContent` instead of innerHTML as innerHTML can be hacked.
document.getElementById("myHeader").textContent = "Heading"
<box>
<p>Hello there!</p>
</box>
<script>
const box = document.querySelector('box');
// Outputs '<p>Hello there!</p>':
console.log(box.innerHTML)
// Reassigns the value:
box.innerHTML = '<p>Goodbye</p>'
</script>
document.getElementById("Test").innerHTML = "<p style='color:red;'>Test</p>";
<!DOCTYPE html>
<html>
<body>
<p id="demo"></p>
//JavaScript can create dynamic HTML content:
<script>
document.getElementById("demo").innerHTML = "Date : " + Date(); </script>
</body>
</html>
<button onclick="this.innerHTML = Date()">The time is?</button>
<p id="demo">code</p>
<script>
function myFunction()
{
var text = document.getElementById("demo").innerHTML;
document.getElementById("demo").innerHTML = text.toUpperCase();
}
</script>