java_script

J

java.inet

internally how to run java script means where to start the evaluation
in the
<head >
tag or
<body> tag and how to run
 
V

VK

internally how to run java script means where to start the evaluation
in the
<head >
tag or
<body> tag and how to run

It depends on the task you want to accomplish.

1) Your script is used as an alternate input stream on page load. In
this case place your script wherever the output has to go:

<body>
.....
<script>
document.write('Hello, world!');
</script>
....
</body>

2) Your script is used to communicate with DOM interface after page
load. In this case place it into head section and run on page load -
so after the DOM Tree is completed. Please note that after that you
cannot use document.write method but only DOM methods - new output
stream on open will clear up the existing page.

<head>
....
<script defer>

function init() {
var p = document.createElement('P');
p.innerHTML = '<strong>Hello, wold!</strong>';
document.body.appendChild(p);
}

window.onload = init;
</script>
....
</head>
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,534
Members
45,007
Latest member
obedient dusk

Latest Threads

Top