jquery - how to check the click is single or double in javascript -


i trying check whether click on element single click or double click.

i trying code.

var clk_ch = document.getelementbyid('clk');  function singleclick() {     alert("single click"); }  function doubleclick() {     alert("double click"); }  var clickcount = 0;  clk_ch.addeventlistener('click', function() {     alert();     clickcount++;     if (clickcount === 1) {         singleclicktimer = settimeout(function() {             clickcount = 0;             singleclick();         }, 400);     } else if (clickcount === 2) {         cleartimeout(singleclicktimer);         clickcount = 0;         doubleclick();     } }, false); 

i not getting alert. going wrong? clk id of clicked element

<input type="image" src="button.gif" id="clk" > 

no need of using settimeout. can add dblclick event listener.

document.addeventlistener("domcontentloaded", function (event) {      var clk_ch = document.getelementbyid('clk');      clk_ch.addeventlistener('click', singleclick, false);     clk_ch.addeventlistener('dblclick', doubleclick, false);  }); 

demo

in jquery:

$('#clk').on('click', singleclick).on('dblclick', doubleclick); 

demo


Comments

Popular posts from this blog

toolbar - How to add link to user registration inside toobar in admin joomla 3 custom component -

linux - disk space limitation when creating war file -

How to provide Authorization & Authentication using Asp.net, C#? -