Use of jQuery Attributes (Attributes) (ii. Class)

Source: Internet
Author: User

This series of articles includes five articles: attribute, class, Html code, text, and value.
This article describes the usage of addClass (class), removeClass (class), and toggleClass (class.
If you have any suggestions or comments on this series of articles, please send to: sjzlgt@qq.com
You can go to the official jQuery website to learn more about jQuery.
. AddClass (class) Usage
Definition: add the specified class name for each matching element.
Returned value: Object
Parameter: class (String): one or more CSS class names to be added to the element. Separate multiple CSS class names with spaces.
Example: add the 'redborder' class to all images in the DIV with ID "div_a1.
Code: $ ("# div_a1 img"). addClass ("redBorder ");

2. removeClass (class) Usage
Definition: deletes all or specified classes from all matching elements.
Returned value: Object
Parameter: class (String): (optional) one or more CSS class names to be deleted. Separate multiple CSS class names with spaces.
Example: Delete the 'redborder' class from all images in the DIV with ID "div_b1.
Code: $ ("# div_b1 img"). removeClass ("redBorder ");

3. toggleClass (class) Usage
Definition: if there is (does not exist), delete (ADD) a class.
Returned value: Object
Parameter: class (String): CSS class Name
Instance: Switch the 'redborder' class to all images in the DIV with ID "div_c1. Code: $ ("# div_c1 img"). toggleClass ("redBorder ");

After running, you need to refresh it to load jqueryXmlns = "http://www.w3.org/1999/xhtml">


JQuery-Attributes (attribute) usage (
Ii. Category)

This series of articles mainly describes how to use Attributes of the jQuery framework (Attributes). I will describe it in the instance mode, which is simple and comprehensive and does not involve
Deep Learning, my learning method: Getting started first, then advanced!

This series of articles includes five articles: attribute, class, Html code, text, and value.

This article describes the usage of addClass (class), removeClass (class), and toggleClass (class.

If you have any suggestions or comments on this series of articles, please send to: sjzlgt@qq.com

You can go to the official jQuery website to learn more about jQuery.
Copyright: code-cat blog: http://www.cnblogs.com/bynet reprint please keep the original author, source and copyright information!1. addClass (class) Usage

Definition: add the specified class name for each matching element.

Returned value: Object

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

Example: add the 'redborder' class to all images in the DIV with ID "div_a1.
Code: $ ("# div_a1 img"). addClass ("redBorder ");
// Click the button to view the effect

Div id = "div_a1"


2. removeClass (class) Usage

Definition: deletes all or specified classes from all matching elements.

Returned value: Object

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

Example: Delete the 'redborder' class from all images in the DIV with ID "div_b1.
Code: $ ("# div_b1 img"). removeClass ("redBorder"); // click the button to view the effect

Div id = "div_b1"


3. toggleClass (class) Usage

Definition: if there is (does not exist), delete (ADD) a class.

Returned value: Object

Parameter: class (String): CSS class Name

Instance: Switch the 'redborder' class to all images in the DIV with ID "div_c1.
Code: $ ("# div_c1 img"). toggleClass ("redBorder"); // click "3" to check the effect.

Div id = "div_c1"


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.