Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

211
Views
How to change change value of variable every time when I click on button

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;
about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

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>

about 4 years ago · Juan Pablo Isaza Report

0

HTML:

<button id="btn" onclick="myfunc()"></button>

js:

    function myfunc() {
      a += 2
    }
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!