Solution to toggle of hidden problems

  • 2020-03-30 01:45:15
  • OfStack

The toggle function was recently used when writing an instance, but the element was hidden when called, and the previous use was just a rotation of events. So I searched the web to see the jQuery API documentation. Finally found out why:
Toggle () has changed since jQuery 1.9. Here are the Notes:
Note: This method signature was deprecated in jQuery 1.8 and removed in jQuery 1.9. JQuery also provides an animation methodumit.toggle () that toggles the visibility of elements The event method is fired the depends on the set of argumentspassed.
In earlier versions, there were two toggles () with the same name, but the methods performed 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.
Later versions removed the first toggle() function, causing the element to be hidden when the toggle function was called.
= = = = = = = = = = = = = = = = = = = = = = = =
Now that this function has been removed, the implementation requirement is still required. How to switch between multiple events?
You can use the click event to determine different conditions to trigger, or you can set a variable to count the number of clicks to execute different functions.
 
var num=0; 
$('#button').click(function(e){ 
if(num++ %2 == 0){ 
//doSomething 
}else{ 
//doOtherSomething 
} 
e.preventDefault(); //Default action for blocking elements (if present)
}); 

Related articles: