Easy Tutorial
❮ Sel Attribute Contains String Value Jquery Traversing Descendants ❯

jQuery toggle() Method

jQuery Event Methods

Example

Toggle colors when a <p> element is clicked:

$("p").toggle(
    function(){$("p").css({"color":"red"});},
    function(){$("p").css({"color":"blue"});},
    function(){$("p").css({"color":"green"});
});

Definition and Usage

The toggle() method adds two or more functions to toggle between for the click event of the selected elements.

The first specified function is called when the element is clicked, the second function is called on the next click, and so on.

Note: There is also a jQuery Effects method named toggle(). Which method is called depends on the parameters provided.


Syntax

Parameter Description
function Required. The function to run each time the selected element is clicked.

More Examples

Toggle Between Multiple Functions


jQuery Event Methods

❮ Sel Attribute Contains String Value Jquery Traversing Descendants ❯