DOM | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
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

21st Jul 2020, 6:38 PM
Obinna
Obinna - avatar
5 Answers
+ 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
21st Jul 2020, 6:57 PM
ebrahem hesham
ebrahem hesham - avatar
+ 1
Obinna Yes it can use to change but how did you do. Can you show your attempts.
21st Jul 2020, 6:52 PM
A͢J
A͢J - avatar
+ 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
21st Jul 2020, 6:54 PM
Obinna
Obinna - avatar
+ 1
Obinna write inside window.onload function and try again. window.onload = function(){ var ele = document.getElementById('demo'); ele.innerHTML = 'Hello World'; }
21st Jul 2020, 6:56 PM
A͢J
A͢J - avatar
0
The window.onload worked. Thanks. Will it be taught later in the lesson?
22nd Jul 2020, 3:09 PM
Obinna
Obinna - avatar