Skip to main content

Posts

Showing posts from May, 2016

Javascript/JQuery Handle Double Click

Recently I have been working on JavaScript/Query & SharePoint client side extensively. I will be posting my learnings during the past one year in the coming few posts.  Recently I was presented with a problem that the custom solution I had provided, did not behave properly when double clicked.  Scrapping through the web, I fumbled on couple of solutions. I personally like the first approach as it is very simple.  First Approach: Click Me $("#clickMe").click(function (e) {     var $this = $(this);     if ($this.hasClass('clicked')){         alert("Double click");         //here is your code for double click         return;     }else{          $this.addClass('clicked');         //your code for single click          setTimeout(function() {                   $this.removeClass('clicked'); },500);     }//end of else }); Second Approach : var DELAY = 700 , clicks = 0 , timer = null ; $ ( function (){ $ ( &