var i = 0;
$('button').click(function() {
i++;
if (i == 1) {
// function 1
} else {
// function 2
i = 0;
}
});
(function($) {
$.fn.clickToggle = function(func1, func2) {
var funcs = [func1, func2];
this.data('toggleclicked', 0);
this.click(function() {
var data = $(this).data();
var tc = data.toggleclicked;
$.proxy(funcs[tc], this)();
data.toggleclicked = (tc + 1) % 2;
});
return this;
};
}(jQuery));
$('#test').clickToggle(function() {
// Function 1
},
function() {
// Function 2
});
Find more questions by tags jQuery
- will.Windl commented on June 8th 19 at 16:45
And anyway, is it possible to delete class from class? - will.Windl commented on June 8th 19 at 16:51
i++;
? In this case, the variable you will always be equal to 1. - citlalli65 commented on June 8th 19 at 16:54- citlalli65 commented on June 8th 19 at 17:03
toggleClass
as written above, but you have in the task description does not say anything about classes. - mellie commented on June 8th 19 at 17:09