Solution to toggle () hiding problems

Source: Internet
Author: User

Solution to toggle () hiding problems

The toggle function is used in an instance, but the elements are hidden during the call. After searching, the cause is found. For more information, see

Recently I used the toggle function when writing an instance, but the elements will be hidden during the call. Previously I used multiple events in turn. 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)

});

 

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.