This series of articles is divided into five articles: attributes, categories, Html code, text, and values.
This article explains: the usage of addClass(class), removeClass(class), toggleClass(class).
If you have any suggestions or comments about this series of articles, please send them to email: sjzlgt@qq.com
You can go to the jQuery official website to learn more about jQuery.
. addClass(class) Usage
Definition: Add the specified class name to each matching element.
Return value: Object
Parameters: class (String): One or more CSS class names to be added to the element, please separate multiple with spaces
Example: DIV with the ID "div_a1" Add the 'redBorder' class to all images in the middle.
Code: $("#div_a1 img").addClass("redBorder");
2. removeClass(class) usage
Definition: from all matching elements Delete all or specified classes.
Return value: Object
Parameters: class (String): (optional) One or more CSS class names to be deleted, please separate multiple with spaces
Instance: Change the ID of "div_b1" Delete the 'redBorder' class for all images in the DIV.
Code: $("#div_b1 img").removeClass("redBorder");
3. toggleClass(class) usage
Definition: If exists (does not exist) ) to delete (add) a class.
Return value: Object
Parameters: class (String): CSS class name
Instance: Switch all images in the DIV with the ID "div_c1" to the 'redBorder' class. Code: $("#div_c1 img").toggleClass("redBorder");
After running, you need to refresh it to load jquery