+ 1

Help! I want to change a js variable using an onclick html function.

Hello all. I want to change var y from 0 to a 4 using an onclick function. What would be the best way to do that?

29th Mar 2017, 8:09 AM
Joe Wild
Joe Wild - avatar
4 Respostas
+ 2
As KC Leung said:: <div id="clickTest">Click me</div> <script type="text/javascript"> var clickTest = document.getElementById ("clickTest") ; var y = 0 ; var onClick = function( e ) { console.log('y was ', y); y = 4 ; console.log('Now y = ' , y); } clickTest.onclick = onClick ; </script>
2nd Apr 2017, 11:18 AM
Ashley Marques
0
var y = 0 ; var onclick = function ( e ) { y = 4 ; }
29th Mar 2017, 8:19 AM
K.C. Leung
K.C. Leung - avatar
0
what would I put in the html?/javascript?
29th Mar 2017, 8:41 AM
Joe Wild
Joe Wild - avatar
0
<div id="clickTest">Click me</div> <script type="text/javascript"> var clickTest = document .getElementById ( "clickTest" ) ; var y = 0 ; var onclick = function ( e ) { y = 4 ; } clickTest.onclick = onclick ; </script>
29th Mar 2017, 9:22 AM
K.C. Leung
K.C. Leung - avatar