please who can help me?😢 | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 11

please who can help me?😢

i have an error in java script which said: uncought typeError: cannot set property 'onclick' of null please who can help me for fixing it😟 this is the code https://code.sololearn.com/WverON6Tt9Yp/?ref=app

20th Aug 2017, 7:44 PM
Ahmed saifaldeen
Ahmed saifaldeen - avatar
10 Answers
+ 11
wrap your entire javascript code with window.onload = function(){ ....your code.... } and leave it as onclick this is caused by the javascript loading before the html and because of that it looks for an element that has not been created yet, thus resulting in am error
20th Aug 2017, 8:12 PM
Burey
Burey - avatar
+ 11
¯\_(ツ)_/¯
20th Aug 2017, 8:22 PM
Burey
Burey - avatar
+ 11
thanks for all @Burey @kamil @Melik Melik Sonmez
20th Aug 2017, 8:38 PM
Ahmed saifaldeen
Ahmed saifaldeen - avatar
+ 10
i changed it to onClick but nothing happen😐
20th Aug 2017, 8:09 PM
Ahmed saifaldeen
Ahmed saifaldeen - avatar
+ 10
@burey is absolutely right, that error occurs because of the order the computer reads your code, in the code playground the computer will read the js before your html, at that point your button isn't alive yet^^
20th Aug 2017, 8:16 PM
Kamil
Kamil - avatar
+ 9
i really really thank you for your good answer
20th Aug 2017, 8:17 PM
Ahmed saifaldeen
Ahmed saifaldeen - avatar
+ 8
yeah burey should get it ^^ I can't see new answers while I'm typing :/
20th Aug 2017, 8:24 PM
Kamil
Kamil - avatar
+ 6
Well thanks I was wondering why that happened
2nd Sep 2017, 2:06 PM
👑 Prometheus 🇸🇬
👑 Prometheus 🇸🇬 - avatar
+ 4
@burey given the answer and Kamil got approval :) by the way i missed the load thing sorry for mis lead
20th Aug 2017, 8:20 PM
Melih Melik Sonmez
Melih Melik Sonmez - avatar
+ 2
line 62 it should be onClick not onclick
20th Aug 2017, 8:06 PM
Melih Melik Sonmez
Melih Melik Sonmez - avatar