$(...).toggle doesn't do anything right away. It simply associates the click events with the selected elements, so that in the future, the click calls one of the two functions that will be called. Thus, the first click does nothing but configure the switch event handler. The second click actually calls the switch event handler. (And also adds another transition event handler! So a third click brings up two event switches, etc.)
.toggle is an alternative to .click , not what you (usually) use inside a .click event .click .
There is no live version of toggle , but you can write it yourself, for example:
function livetoggle(selector, f0, f1) { $(selector).live('click', function(event) { var t= $(this).data('livetoggle'); $(this).data('livetoggle', !t); (t? f1 : f0).call(this, event); }); } livetoggle('a.divToggle', function() { ... }, function() { ... });
source share