Change button text by clicking

0

I would like to know how I can change the button text every time I click on it, as if it were a list-group when it clicks it opens and closes, I made this code:

function trocarFlecha()
{
  var x = document.getElementById('btnImage').value;
  if (x = "Imagem  ˅") {
    document.getElementById('btnImage').innerHTML = "Imagem  ˂"; 
  } else {
    document.getElementById('btnImage').innerHTML = "Imagem  ˅";
  }
}

And I added a onclick="trocarFlecha()" to the button and it only changes once but I wanted to do it dynamically, doing that every time I click it it changes.

    
asked by anonymous 06.09.2018 / 15:06

1 answer

-1

Change = by === to:

if (x = "Imagem ˅") {
    ....
}

EDIT: do so,

var cliquei = false;
function trocarFlecha()
{
  var x = document.getElementById('btnImage').value;
  if (cliquei = !cliquei) {
    document.getElementById('btnImage').value = "Imagem  ˂"; 
  } else {
    document.getElementById('btnImage').value = "Imagem  ˅";
  }
}
    
06.09.2018 / 15:25