+ 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
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>
+ 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.
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