Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

210
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar

0

HTML:

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

js:

    function myfunc() {
      a += 2
    }
about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda