jQuery .toggle() event handler

Syntax and Description

.toggle(handlerEven, handlerOdd[, additionalHandlers...])
  • handlerEven is a function to execute every even time the element is clicked
  • handlerOdd is function to execute every odd time the element is clicked
  • additionalHandlers (optional) are additional handlers to cycle through after clicks

Return value is the jQuery object, for chaining purposes.

toggle method binds two or more handlers to the matched elements, to be executed on alternate clicks.

For example:


<div id="target">
   Click here
</div>

Event handlers can then be bound to the <div>.


$('#target').toggle(function() {
    $.print('First ');
}, function() {/*from  ww  w .j av a  2  s.c  o m*/
    $.print('Second');
});




















Home »
  jQuery »
    jQuery Tutorial »




Basics
Selector
DOM
Event
Effect
Utilities