+ 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 odpowiedzi
+ 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
var y = 0 ;
var onclick = function ( e ) {
y = 4 ;
}
0
what would I put in the html?/javascript?
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>