JQuery click

by Thangaraja Chinnathambi

HTML

<script src="https://code.jquery.com/jquery-2.2.0.min.js"></script>
<p id="clickable">Click on this paragraph.</p>
<p id="main">
I will change on clicking
</p>

JavaScript

$(function() {

  var clicks = 0;
  var timer = null;

  $("#clickable").on("click", function(e) {
      clicks++; // Increment click counter
      if (clicks === 1) {
        timer = setTimeout(function() {
          $('#main').text('Single click');
					
					// Add single click event code
					
					
          clicks = 0; //Reset
        }, 800); // Increase or decrease if there is slowness or speed
      } else {
        clearTimeout(timer); //prevent single-click action
        $('#main').text('Double click');
				
				// Add double click event code
				
        clicks = 0; // Reset
      }
    });

    $("#clickable").on("dblclick", function(e) {
      e.preventDefault(); //Prevent double click
    });

});