Toggle () how to hide the problem _ jquery-js tutorial

Source: Internet
Author: User
The toggle function is used in an instance, but the elements are hidden during the call. After searching, the cause is found, you can refer to the toggle function used when you compile an instance recently, but the elements will be hidden when you call the function. It is only a matter of switching multiple events that you have used before. The best way to do this is to search and view the jQuery API documentation on the internet. I finally found the cause:
After jQuery 1.9, toggle () has changed. The following is the official Notes:
Note: This method signature was deprecated in jQuery 1.8 and removed in jQuery 1.9. jQuery also provides an animation methodnamed. toggle () that toggles the visibility of elements. whether the animation or the event method is fired depends on the set of argumentspassed.
In earlier versions, there were two toggle () with the same name, but the methods executed were different:
. Toggle (handler (eventObject), handler (eventObject) [, handler (eventObject)])
Description: Bind two or more handlers to the matched elements, to be executed on alternate clicks.
========================================================== ==================
. Toggle ([duration] [, complete])
Description: Display or hide the matched elements.
In later versions, the first toggle () function is removed, causing the elements to be hidden when the switching function is called.
======================================
Since this function is removed, the implementation requirement is still required. How can we achieve switching between multiple events in turn?
You can use the click event to determine different conditions, or set a variable to count the number of clicks to execute different functions.

The Code is as follows:


Var num = 0;
$ ('# Click'). click (function (e ){
If (num ++ % 2 = 0 ){
// DoSomething
} Else {
// DoOtherSomething
}
E. preventDefault (); // block the default action of an element (if any)
});

Related Article

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.