I should add, that w3schools example is somewhat lacking there, in that they only show you the method of quoting the code to be executed after the delay period. Quoting the code is undesirable, as the string compiler (one of the slowest parts of executing javascript, along with accessing DOM elements) has to start up. It is much better to feed setTimeout the name of a function to run (without quotes or parens () ) or else feed it an anonymous function which contains the code or function with parameters to be run. A better example or two:
Code:
<script type="text/javascript">
function myFunction() {
alert("Hello from myFunction!");
}
function myFunctionWithParameters(parameter1,parameter2) {
parameter1.style.display = parameter2;
}
window.onload = function () {
window.setTimeout(myFunction,3000); //3000 milliseconds = 3 seconds
window.setTimeout(function () { myFunctionWithParameters(document.getElementById('someDiv'), "block"); },6000);
};
</script>
<div id="someDiv" style="display:none;">some text in someDiv</div>
Bookmarks