I have bined function like this(simplified version):
$('label').bind('click hover', function() {
$('label').removeClass("active");
$(this).addClass("active");
});
How can I add an if
to check if it is a click?
I have bined function like this(simplified version):
$('label').bind('click hover', function() {
$('label').removeClass("active");
$(this).addClass("active");
});
How can I add an if
to check if it is a click?
1 Answer
Reset to default 8Use event.type
:
$('label').bind('click hover', function(event) {
if(event.type == 'click') {
// do stuff
}
$('label').removeClass("active");
$(this).addClass("active");
});
Demo: http://jsfiddle/jtbowden/sqvDy/
Note, the demo uses .on()
, which is the new method of event binding for jQuery 1.7+, replacing .bind()
, .live()
, and .delegate()
.