Why does it work??? I made a type mistake so how? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Why does it work??? I made a type mistake so how?

I made in the shop a span with the id "swallet", but in my javascript i make a var swallet=$("swaller"); which does the same as document.getElementById("swaller") for the non-jquery persons. but if you look carefull to the id's, you might notice there is a difference html id="swallet" javascript var swallet = $("swaller") its not the same id, but if you start the game it will just work correctly and shows your money in the shop too https://code.sololearn.com/WuU3yGBHAGLO/?ref=app line 21 in html and line 61 in javascript

31st May 2018, 5:29 AM
Roel
Roel - avatar
2 Answers
0
Its because you are not really using jquery. You are only selecting it in the context of onload and saving it in a local variable. That variable is lost when you exit the onload event. The way javascript work on newer browsers will allow you to address html elements by id without actually selecting it provided that the id value was not used for something else. https://code.sololearn.com/Weq2zKdl0Byj/?ref=app
31st May 2018, 5:59 AM
Nommer101
Nommer101 - avatar
0
wow thanks, this will help me a lot with saving me from extra codelines
31st May 2018, 6:09 AM
Roel
Roel - avatar