jQuery toggle () method
Examples
Click on the color switch <p> element when:
$("p").toggle(
function(){$("p").css({"color":"red"});},
function(){$("p").css({"color":"blue"});},
function(){$("p").css({"color":"green"});
});
function(){$("p").css({"color":"red"});},
function(){$("p").css({"color":"blue"});},
function(){$("p").css({"color":"green"});
});
try it"
Definition and Usage
toggle () method in jQuery version 1.8 is obsolete and is removed in version 1.9.
toggle () method to add two or more functions in response to the switching of the selected element click events.
The first specified function is called when the element is clicked, call the second function when you tap again, and so on.
Note: there is a named toggle () in jQuery effect methods. Depending on the parameters to determine which method call.
grammar
$(selector).trigger( function )
参数 | 描述 |
---|---|
function | 必需。每当被选元素被点击时要运行的函数。 |
More examples
Switching between multiple functions
How to switch between multiple functions.