+ 1

what am i doing wrong here?

They say JS global variables should be declared outside of the functions but I have been trying without success. I would like to declare several variables to be used on different functions. how am I getting this wrong? https://code.sololearn.com/W8YPA4z49efz/?ref=app

23rd Oct 2018, 10:02 AM
Dzeff
Dzeff - avatar
3 ответов
+ 6
<!DOCTYPE html> <html> <head> <title>Page Title</title> </head> <body> <p> <button onclick = "demo = document.getElementById('demo');change()">CHANGE</button> </p> <div id = "demo"></div> </body> </html>
23rd Oct 2018, 10:08 AM
Googel
Googel - avatar
+ 5
Before you trigger event in HTML page you need to first declare variable demo as demo = document.getElementById('demo'); in the same HTML page's event attribute.
23rd Oct 2018, 4:45 PM
Googel
Googel - avatar
0
5667ce7f99078110265cec8b75482e4ea7055780 I am trying hard to understand your example. All I wanted was how global variables should be declared in for example an external JS
23rd Oct 2018, 11:19 AM
Dzeff
Dzeff - avatar