Saturday, May 11, 2024
 Popular · Latest · Hot · Upcoming
107
rated 0 times [  110] [ 3]  / answers: 1 / hits: 85711  / 11 Years ago, sat, february 16, 2013, 12:00:00

Is there a way to run two functions similar to this:



$('.myClass').click(
function() {
// First click
},
function() {
// Second click
}
);


I want to use a basic toggle event, but .toggle() has been deprecated.


More From » jquery

 Answers
122

Try this:



$('.myClass').click(function() {
var clicks = $(this).data('clicks');
if (clicks) {
// odd clicks
} else {
// even clicks
}
$(this).data(clicks, !clicks);
});


This is based on an already answered question: Alternative to jQuery's .toggle() method that supports eventData?


[#80186] Thursday, February 14, 2013, 11 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
patienceannel

Total Points: 674
Total Questions: 101
Total Answers: 101

Location: Northern Mariana Islands
Member since Fri, Jan 15, 2021
3 Years ago
;