Jquery snap click and freeze how to check if click

I combined a function like this (simplified version):

$('label').bind('click hover', function() { $('label').removeClass("active"); $(this).addClass("active"); }); 

How can I add if to check if it is a click?

+6
source share
1 answer

Use event.type :

 $('label').bind('click hover', function(event) { if(event.type == 'click') { // do stuff } $('label').removeClass("active"); $(this).addClass("active"); }); 

Demo: http://jsfiddle.net/jtbowden/sqvDy/

Note. The demo uses .on() , which is the new event binding method for jQuery 1.7+, replacing .bind() , .live() and .delegate() .

+8
source

Source: https://habr.com/ru/post/911363/


All Articles