-
On page load run script
Hi there,
I am hoping to add some text to a div using the append method in JS.
So far I ahve this:
Code:
function createDiv()
{
var pTag = document.createElement("p");
pTag.innerHTML = "This paragraph <b>HTML p tag</b> is added dynamically inside the div tag.";
document.getElementById("ctl00_MiWebC_pnlLogin").appendChild(pTag);
}
How ever this code only works if there is an input button with an onclick event handler on it (createDiv();).
Is there a way I can get this script to automatically run without the onclick. I.e on page load.
I cannot access the body html tag so I cannot set it there.
Would something like this work ?
Code:
<script type="text/javascript" language="javascript">
{
var pTag = document.createElement("p");
pTag.setAttribute("align","center");
pTag.innerHTML = "This paragraph <b>HTML p tag</b> is added.";
document.getElementById("div1").appendChild(pTag);
}
</script>
Thank you all :)
-
Code:
window.onload=function(){
// expressions, statements, functions, etc
}
-