I have the follwing JavaScript.
document.write can only be used during the initial loading of the document.
If you want to insert your H1 when the function is called, you may replace
document.write(" Just a javascript demo
");
with
var h1 = document.createElement('h1');
h1.innerHTML = " Just a javascript demo";
document.body.appendChild(h1);