T X
0
Q:

how to make a button do different functions on different clicks

<button id="clickme">Click Me</button>
<script>
  function one() {
     alert('one clicked');
     document.getElementById('clickme').onclick = two;
  }

  function two() {
   alert('two clicked');
  }

  document.getElementById('clickme').onclick = one;
</script>
0
var callOne = true;

function one() {
   alert('Call one');
}

function two() {
   alert('Call two');
}

function call(){
   if(callOne) one();
  else two();
  callOne = !callOne;
}
0
var fn3 = (function() {
  var first = true;
  return function() {
    first ? fn1() : fn2();
    first = !first;
  }
})();

function fn1() {
  console.log(1);
};
function fn2() {
  console.log(2);
};
0

New to Communities?

Join the community