.toggle()

In this chapter you will learn:

  1. Syntax and Description for .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() {
    $.print('Second');
});

Next chapter...

What you will learn in the next chapter:

  1. Syntax and Description for .trigger() event
  2. How to trigger focus event
  3. How to trigger mouse over event
  4. How to trigger click event
  5. How to trigger the change event
  6. How to trigger a custom event
Home » jQuery » Event
Event
Event attributes
event.keycode
event.clientX/clientY
pageX/pageY
Cancel event
Event target
bind
.blur()
.change()
.click()
.error()
.dblclick()
.delegate()
.die()
.focus()
.hover()
.keydown()
.keypress()
.keyup()
.live()
.load()
.mousedown()
.mouseenter()
.mouseleave()
.mousemove()
.mouseover()
.mouseout()
.mouseup()
.off()
.on()
.one()
.ready()
.resize()
.scroll()
.select()
.submit()
.toggle()
.trigger()
.triggerHandler()
.unbind()
.undelegate()
.unload()