Is there something im missing about the "document.getElementById().innerHTML" | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 2

Is there something im missing about the "document.getElementById().innerHTML"

some how when i started i said this was going to be easy because ive done it multiple times in my money counter but when i try a simple code like this one below it seems to be having an output error which is making me irritated over this simple objective that is very very basic so im gonna ask for help even though its gonna make me look like a fool maybe im missing something but anyway all i want is the output to display https://code.sololearn.com/WoYSIEgOB7EQ/?ref=app

8th Jun 2018, 4:08 AM
Brennan Woodroof
Brennan Woodroof - avatar
7 Answers
+ 10
The problem here is that your script executes before the document loads. Fix this by wrapping your script in a function and calling it after the document loads. window.onload = function(){ var so1=0.07 * 16; var so1a=so1 + 1.25; var so1b=so1a.toFixed(2); document.getElementById("so1c").innerHTML = so1b; }
8th Jun 2018, 4:14 AM
Hatsy Rei
Hatsy Rei - avatar
+ 8
this seemed to work for me window.onload = function(){ // your javascript code } putting this makes sure the document is completely loaded before you can manipulate the elements, otherwise you could be setting the inner HTML of an element that doesn't exist (not loaded yet)
8th Jun 2018, 4:19 AM
MCJEH
MCJEH - avatar
+ 4
you can discuss it on this app in a sololearn server (group chat) https://www.sololearn.com/discuss/689391/?ref=app
10th Jun 2018, 5:02 AM
MCJEH
MCJEH - avatar
+ 2
thank you so much spend about an hour and a half trying to figure whats wrong or what i did wrong
8th Jun 2018, 4:17 AM
Brennan Woodroof
Brennan Woodroof - avatar
0
hi
8th Jun 2018, 7:39 PM
Agus Zarkasih
0
Hey Guys I need help with an assignment for school
9th Jun 2018, 9:06 AM
Nicole Beta
Nicole Beta - avatar
0
html ob = document.getElementById(" "); .innerHTML = "Hi"; help
18th Mar 2021, 5:33 AM
Vincent Santiago
Vincent Santiago - avatar