same funtion depending on what button is clicked code example

Example 1: 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>

Example 2: 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;
}

Tags:

Misc Example