. Toggle (function, function, ...)
Link . Toggle (function, function, ...) removed This is the "click a element to run the specified functions" signature of. Toggle (). It should not being confused with the ' change the visibility of an element ' of the. Toggle () which is not deprecated. The former is being removed to reduce confusion and improve, the potential for modularity in the library. The JQuery Migrate plugin can be used to restore the functionality. |
It is important to note that the. Toggle () is "bind two or more handlers, loop execution when clicked"; the other. Toggle () still exists, which is "controlling the display and concealment of the corresponding component"; Chinese is obscure, the official description of the two methods is as follows:
categories:deprecated > Deprecated 1.8 | Events > Mouse Events . Toggle (Handler (eventobject), Handler (EventObject) [, Handler (EventObject)])Returns:jQuery Version deprecated:1.8, removed:1.9Description: Bind, or more handlers to the matched elements, to being executed on alternate clicks. |
Categories:effects > Basics . Toggle ([duration] [, complete])Returns:jQueryDescription: Display or hide the matched elements. |
This change deserves attention. For the deletion of this ". Toggle ()" Method, the official did not give the upgrade measures, but I found a method name and description are more similar to the method ". Trigger ()", do not know can be substituted.
I use version 2.0.0 to perform the following version:
$ (function () {
$ ("h5"). Toggle (function () {
$ (this). Next ("Div"). Show ();
}, function () {
$ (this). Next ("div"). Hide ();
});
});
You want to use toggle () to control the click of a div, but why does the title and div fade away when you open the page?
Because. Jquery1.9.1 Toggle (Fn1,fn2 ... ) method allows you to click on an element to execute the specified function. This method is removed to reduce clutter and increase the potential modularity level. Only show and hide features are preserved!
Official website: http://api.jquery.com/toggle/
Original workaround: Global one counter=0 Click event to judge Counter%2==0 to trigger different CSS respectively, then counter++, simple and rude.
Or use a state machine, you can see the article written by Nanyi.