Jquery learns the second property (class)

Source: Internet
Author: User

AddClass (class) adds the specified class name for each matching element. Adds the specified class (es) to each of the set of matched elements. Return Value

JQuery

Parameters

Class(String): one or more CSS class names to be added to the element. Separate them with spaces.

Example

Add the 'selected' class to the matched element.

HTML code:

<P> Hello </p>

JQuery code:

$ ("P"). addClass ("selected ");

Result:

[<P class = "selected"> Hello </p>]

Add the selected highlight class to the matched element

HTML code:

<P> Hello </p>

JQuery code:

$ ("P"). addClass ("selected highlight ");

Result:

[<P class = "selected highlight"> Hello </p>] ------------------------------------------------------------------------------------------------------------------------------ removeClass (class) deletes all or specified classes from all matching elements. Removes all or the specified class (es) from the set of matched elements. Return Value

JQuery

Parameters

Class(String): (optional) one or more CSS class names to be deleted. Separate them with spaces.

Example

Delete the 'selected' class from the matched element.

HTML code:

<P class = "selected first"> Hello </p>

JQuery code:

$ ("P"). removeClass ("selected ");

Result:

[<P> Hello </p>]

Delete all classes of matching elements

HTML code:

<P class = "selected first"> Hello </p>

JQuery code:

$ ("P"). removeClass ();

Result:

[<P> Hello </p>] When toggleClass (class) exists (does not exist), delete (ADD) a class. Adds the specified class if it is not present, removes the specified class if it is present. Return Value

JQuery

Parameters

Class(String): CSS Class Name

Example

Switch the 'selected' class to the matching element.

HTML code:

<P> Hello </p> <p class = "selected"> Hello Again </p>

JQuery code:

$ ("P"). toggleClass ("selected ");

Result:

[<P class = "selected"> Hello </p>, <p> Hello Again </p>]

Related Article

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.