jquery Toggle Method

Source: Internet
Author: User
Tags deprecated

. 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.9

Description: Bind, or more handlers to the matched elements, to being executed on alternate clicks.

Categories:effects > Basics

. Toggle ([duration] [, complete])Returns:jQuery

Description: 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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.