how to get a toggle button to do different js functions

Solutions on MaxInterview for how to get a toggle button to do different js functions by the best coders in the world

showing results for - "how to get a toggle button to do different js functions"
Sakina
27 Oct 2018
1var clicked = false;
2
3function toggleBtnClick() {
4  var img = document.getElementById('baseImg');
5  if (clicked) {
6    img.src = 'http://via.placeholder.com/350x150/e9e9e9/000000';
7    clicked = false;
8  } else {
9    img.src = 'http://via.placeholder.com/350x150/3fafed/000000';
10    clicked = true;
11  }
12}