<pclass="arguement"><strong>handler(eventObject)</strong>A function to execute every even time the element is clicked.</p>
<pclass="arguement"><strong>handler(eventObject)</strong>A function to execute every odd time the element is clicked.</p>
<pclass="arguement"><strong>handler(eventObject)</strong>Additional handlers to cycle through after clicks.</p>
</li></ul>
<divclass="longdesc">
<p>The <code>.toggle()</code> method binds a handler for the <code>click</code> event, so the rules outlined for the triggering of <code>click</code> apply here as well.</p>
<p>Event handlers can then be bound to the <code><div></code>:</p>
<pre>$('#target').toggle(function() {
alert('First handler for .toggle() called.');
}, function() {
alert('Second handler for .toggle() called.');
});</pre>
<p>As the element is clicked repeatedly, the messages alternate:</p>
<p>
<spanclass="output">First handler for .toggle() called.</span><br><spanclass="output">Second handler for .toggle() called.</span><br><spanclass="output">First handler for .toggle() called.</span><br><spanclass="output">Second handler for .toggle() called.</span><br><spanclass="output">First handler for .toggle() called.</span>
</p>
<p>If more than two handlers are provided, <code>.toggle()</code> will cycle among all of them. For example, if there are three handlers, then the first handler will be called on the first click, the fourth click, the seventh click, and so on.</p>
<p>The <code>.toggle()</code> method is provided for convenience. It is relatively straightforward to implement the same behavior by hand, and this can be necessary if the assumptions built into <code>.toggle()</code> prove limiting. For example, <code>.toggle()</code> is not guaranteed to work correctly if applied twice to the same element. Since <code>.toggle()</code> internally uses a <code>click</code> handler to do its work, we must unbind <code>click</code> to remove a behavior attached with <code>.toggle()</code>, so other <code>click</code> handlers can be caught in the crossfire. The implementation also calls <code>.preventDefault()</code> on the event, so links will not be followed and buttons will not be clicked if <code>.toggle()</code> has been called on the element.</p>
</div>
<h3>Examples:</h3>
<divid="entry-examples"class="entry-examples">
<divid="example-0">
<h4>Example: <spanclass="desc">Click to toggle highlight on the list item.</span>
<h4>Example: <spanclass="desc">Animates all paragraphs to be shown if they are hidden and hidden if they are visible, completing the animation within 600 milliseconds.</span>