0
DOM
Why doesn't it run in browser when i type document.getElementById in notepad??. Because i learnt in my current lesson that it can be used to change div elements. Pls help
5 odpowiedzi
+ 2
First review the id name given to the div and the id you used in your JavaScript file in case of any faults or different letters between them
Second ensure that you've attaching your JavaScript file and include it in your html file in the true way
Last check the syntax of the code it should be something like that
As you see in my attempt i gave div id name of "JavaScript" so that my code should be typed in that syntax as following
Var Y =document.getElementById
("JavaScript");
And again pay attention for the letters case on both JavaScript and html files
+ 1
Obinna Yes it can use to change but how did you do. Can you show your attempts.
+ 1
No output to my code
var elem = document.getElementById("demo");
elem.innerHTML ="Hello World";
Is there anything wrong with the code 'cause its not giving any output when i run it in browser
+ 1
Obinna write inside window.onload function and try again.
window.onload = function(){
var ele = document.getElementById('demo');
ele.innerHTML = 'Hello World';
}
0
The window.onload worked. Thanks. Will it be taught later in the lesson?