0
you need to wait for page to load first,try this way :
window.onload = function () {
var c = 2; d = 3, e = c + d;
document.getElementById('p1').innerHTML = e;
}
if you are using jquery, you can use
(document).ready(function() {
//your code here
});
0
Hi,<br><br>
Script will work if it is written on body or head tag. But the problem is that, you are trying to assign innerhtml of p tag from head. That wont work, as while running your script in head tag that p element is not loaded in the body. Hence script can't find any p element with that id.