event to control the doubleClick

2

I have managed to perform a function in the first click

function s(){
      $('div').addClass('s');
      $('div').css({display:"block"});
      console.log("click");
}
      
    	 
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<button onclick="s()">Haz Click!</button>

But I do not know how to detect the second click

    
asked by ger 05.03.2018 в 02:18
source

3 answers

5

You can set a variable clics and from there you can determine how many clicks the user is making on that button

var clics = 0;
function s() {
    if(clics == 0) {
       //primer clic
    }
    else {
        //segundo clic
    }
    ++clics;
}
    
answered by 05.03.2018 / 02:25
source
0

For a double click event you can use this:

$( "#target" ).dblclick(function() {
  alert( "Handler for .dblclick() called." );
});

Greetings

    
answered by 05.03.2018 в 06:38
0

the listeners have a function called dblclick , an example using click and double click, you must be careful with this I recommend you use one or the other to avoid confusion

miDobleClick.addEventListener("dblclick" , function(){
console.info("chispas doble click")
})
miDobleClick.addEventListener("click" , function(){
console.log("mantengo mi click")
})
<button id="miDobleClick">Haz Click!</button>
    
answered by 05.03.2018 в 14:26