Hello,
I was looking for alternative of jquery toggle and came across this code:
$('a').click(function() {
var clicks = $(this).data('clicks');
if (clicks) {
alert('odd number of clicks');
} else {
alert('even number of clicks');
}
$(this).data("clicks", !clicks);
});
I tried it and it works, but I can’t figure out what it does. I see that it creates a variable that hold data in my element. However, I don’t understand the rest of the code. Esp. I don’t understand what this line $(this).data(“clicks”, !clicks); does.