I have two variables and I need to add number on value that is already inside variable every time when I click on button.
This is my code:
var x = e.pageX;
var y = e.pageY;
I have x an y variable and I need to add on x 30 and on y 22 every time when I click on button.But right now when I click on button I add this number just once and when I click again nothing happened.
var xLeft = x 30;
var yTop = y 22;
CodePudding user response:
Please check following example
var x = 10
var y = 20
var xLeft=0
var yTop=0
function clickFunction() {
xLeft = x 30
yTop = y 22
console.log("xLeft :" xLeft)
console.log("yTop :" yTop)
}
<!DOCTYPE html>
<html>
<body>
<button type="button" onclick="clickFunction()">Click Me!</button>
</body>
</html>
CodePudding user response:
HTML:
<button id="btn" onclick="myfunc()"></button>
js:
function myfunc() {
a = 2
}
