-2

i don't want to use the double click function , instead i just want to run the below buttonOnClick() when a user click two times not single time , Help me iam new to coding

                <button onclick="buttonOnClick();" onmouseover="mouseOver();" onmouseout="mouseOut();">Subscribe <i id="ytb" class="fa fa-youtube-square ytb"></i></button>
                <br>


             </div>

function buttonOnClick()

{


  window.open('https://www.youtube.com/channel/UCXE6pw29K2lHS_2fB8LeU1Q?sub_confirmation=1','_blank');



  setTimeout(aTagChange, 12000);

}

2 Answers2

3

Set a variable prevClick then update and check it:

var prevClick = false;
function buttonOnClick() {
    if (prevClick) {
        window.open('https://www.youtube.com/channel/UCXE6pw29K2lHS_2fB8LeU1Q?sub_confirmation=1','_blank');
        setTimeout(aTagChange, 12000);
    } else {
        prevClick = true;
    }
}
Jack Bashford
  • 40,575
  • 10
  • 44
  • 74
2

You can use ondblclick

function func(){
  console.log("double clicked");
}
<button ondblclick="func()">Subscribe <i id="ytb" class="fa fa-youtube-square ytb"></i></button>
You can have a Boolean to check if the its clicked once or not

let clicked = false;
function func(){
  if(clicked === false){
    clicked = true;
    return false;
  }
  else clicked = false;
  console.log("clicked second time");
  
}
<button onclick="func()">Subscribe <i id="ytb" class="fa fa-youtube-square ytb"></i></button>
Maheer Ali
  • 34,163
  • 5
  • 36
  • 62