Reputation: 48
I want to know that this example fires on second click not at first click, why? i am using delegate function. the example is http://jsfiddle.net/3avaG/.
I need this solution badly.
Thank you.
Upvotes: 1
Views: 468
Reputation: 13957
Delegate has been depreciated and therefore won't work with jQuery 1.8. Change the version in your JSFiddle to 1.5 for example and it's fine.
From the docs:
As of jQuery 1.7, .delegate() has been superseded by the .on() method. For earlier versions, however, it remains the most effective means to use event delegation. More information on event binding and delegation is in the .on() method.
UPDATE:
$('body').delegate('#as', 'click', function(e){
$(this).toggle(function() {
alert("First");
}, function() {
alert("Second");
});
});
Upvotes: 2