Answers for "how to make a button do different functions on different clicks"

0

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>
Posted by: Guest on July-06-2020
0

how to make a button do different functions on different clicks

var callOne = true;

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

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

function call(){
   if(callOne) one();
  else two();
  callOne = !callOne;
}
Posted by: Guest on July-06-2020
0

how to make a button do different functions on different clicks

var fn3 = (function() {
  var first = true;
  return function() {
    first ? fn1() : fn2();
    first = !first;
  }
})();

function fn1() {
  console.log(1);
};
function fn2() {
  console.log(2);
};
Posted by: Guest on July-06-2020

Code answers related to "how to make a button do different functions on different clicks"

Code answers related to "Javascript"

Browse Popular Code Answers by Language