jQuery detect click amount

How to detect the amounts of clicks you do on an element. This is helpful on changing an element on amounts of clicks.

This function i used it in one of my projects to add a class when i clicked it and then removed the class when i clicked it twice. So this can be used in your projects lets say you want to turn the element red when you click it one and then turn it blue when you click it again. I leave you this small snippet. 

$( document ).ready(function() {
    		var clickCount = 0;
				clickCount = (clickCount == 2) ? 0:clickCount;
				if(clickCount == 0){
					alert("1st click");
				}else if(clickCount == 1){
					alert("2nd clicks");

 View Demo