Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

214
Visualizações
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 Respostas
Responde à pergunta

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 Relatório

0

HTML:

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

js:

    function myfunc() {
      a += 2
    }
about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda