+ 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?
4 Answers
+ 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>
0
what would I put in the html?/javascript?