Reputation: 4517
I have a click event that needs to be fired not more than once :
$(".menuIco").one('click', function() {
$(this).menuIcoClick($(this));
});
...that leads to function :
$.fn.menuIcoClick = function(menuIco) {
[...does some animations, not important...]
}
However, after other event I would like that event to be able to fire up again. I'm trying to bind menuIco
's click event with menuIcoClick
function again using on()
:
.on('click', $('#analiza').menuIcoClick($('#analiza')));
in
$("#icoBack").click(function() {
$('#analiza').animate({left: ($("#analiza").data("left")), top: ($("#analiza").data("top"))}, 0).on('click', $('#analiza').menuIcoClick($('#analiza')));
});
but it doesn't work, on()
method doesn't let me click (and fire up once-only event) on that element again, as I expected.
Upvotes: 2
Views: 487
Reputation: 1964
You can use the .off
inside your first function:
$(".menuIco").on('click', function() {
$(this).menuIcoClick($(this));
$(".menuIco").off('click'); // Here we disable the event, on the first execution
});
For do the event again you need to set it into a new function, attached to event that you want.
If this not work, please send us a jsfiddle showing up with more details your problem.
Upvotes: 1