The toggle () event mainly switches the visible state of elements. The following describes how to use JQuery's toggle to automatically display the toggle () event after webpage loading. It mainly switches the visible state of elements.
1. toggle (switch) ① switch is an optional value. If this parameter is left blank, the original element is displayed and hidden.
HTML code:
The Code is as follows:
Hello
Hello Again
JQuery code:
The Code is as follows:
$ ("P"). toggle ()
Result:
The Code is as follows:
Hello
Hello Again
② If the switch has a value, the value is TRUE or false. If the switch is TRUE, the element is displayed. If the switch has a value, the element is hidden.
HTML
The Code is as follows:
Hello
JQuery
The Code is as follows:
Var I = 0;
$ ("# B"). click (function (){
$ ("# Tt"). toggle (I ++ % 2 = 0 );
});
2. toggle (speed, [callback]) speed is an optional parameter. It indicates the animation speed of an element. The element is displayed or hidden by sliding the animation, its value can be (slow, normal, fast); [callback] is the method that can be executed by the function.
HTML code
The Code is as follows:
Hello Again
JQuery code
The Code is as follows:
$ ("# T"). toggle ("slow", function (){
Alert ("123456 ");
});
That is, when the second method is used to hide speed, the page can be loaded to automatically play the screen.