How jquery determines whether an element is clicked, attributes manipulated, class manipulated

Source: Internet
Author: User

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

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.