1, by clicking the event, change the value of the flag, record the click Status
1 function () {2varfalse; 3 $ (' #test '). Click (functiontrue;}); 4 $ (' #show '). Click (function() {alert (Isclick);}) 5 }
2, adding and deleting class:$ (' #id '). AddClass (), $ (' #id '). Removeclass ()
3. Gets the Set element value: $ ('. class '). Text (), $ (' #id '). HTML (), $ ('. class '). Val ()
4. Add attributes or Modify property values: $ (' #id '). attr ({' style ': ' Display:none '})
5, Toggle ()
Definition and usage
The toggle () method Toggles the visible state of the element.
If the selected element is visible, the elements are hidden and displayed if the selected element is hidden.
Syntax: $ (selector). Toggle (Speed,callback,switch)
Parameters |
Description |
Speed |
Optional. Specifies that the element is visible to the hidden speed (or vice versa). The default is "0". Possible values:
- milliseconds (e.g. 1500)
- "Slow"
- "Normal"
- "Fast"
In the case of setting the speed, the element gradually changes its height, width, margin, padding, and transparency as it is visible to the hidden process. If you set this parameter, you cannot use the switch parameter. |
Callback |
Optional. The function to execute after the toggle function finishes executing. To learn more about callback, please visit our jQuery callback chapter. This parameter cannot be set unless the speed parameter is set. |
Switch |
Optional. Boolean value. Specifies whether toggle hides or displays all selected elements.
- True-Show all elements
- False-Hides all elements
If this parameter is set, the speed and callback parameters cannot be used. |
Hints and Notes
Note: This effect applies to elements hidden through jquery, or to declarations of display:none elements in CSS (but not for visibility:hidden elements)
How jquery determines whether an element is clicked, attributes manipulated, class manipulated