Home > Web Front-end > JS Tutorial > The use of jQuery Attributes (Part 2, Category)_jquery

The use of jQuery Attributes (Part 2, Category)_jquery

WBOY
Release: 2016-05-16 18:38:55
Original
946 people have browsed it

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


[Ctrl+A 全选 注:如需引入外部Js需刷新才能执行]


源码打包下载
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template