Home >Web Front-end >JS Tutorial >Example of usage of removeClass() method in jQuery_jquery

Example of usage of removeClass() method in jQuery_jquery

WBOY
WBOYOriginal
2016-05-16 16:22:081629browse

The example in this article describes the usage of the removeClass() method in jQuery. Share it with everyone for your reference. The specific analysis is as follows:

This method removes one or more classes from the matching element.
According to the different method parameters, there are the following syntax structures.

Grammar structure 1:
Method has no parameters. Remove all classes from matching elements.

Copy code The code is as follows:
$(selector).removeClass()

Example code:

The code can delete all css classes of the div.

Copy code The code is as follows:






removeClass() function-Script Home





Script Home welcomes you




Grammar structure 2:

Remove the specified class from the matching element

Copy code The code is as follows:
$(selector).removeClass(class)

参数 描述
class 一个或多个要删除的CSS类名。类名之间用空格分隔。

Example code:

Example 1:

Copy code The code is as follows:






removeClass() function-Script Home





Script Home welcomes you




Remove a specified class.

Example 2:

Copy code The code is as follows:






removeClass() function-Script Home





Script Home welcomes you




Remove two CSS classes, separated by spaces between class names.

Grammar structure three:

Copy code The code is as follows:
$(selector).removeClass(function(index,oldclass))

The function returns the class name to be removed.

Parameter list:

参数 描述
function(index,oldclass) 方法返回一个或多个空格分隔的要被移除的class名。
index - 可选,接受选择器的index 位置。
oldclass - 可选,接受选择器的原有类值。

Example code:

Example 1:

Copy code The code is as follows:






removeClass() function-Script Home





Script Home welcomes you




Use a function as a parameter, and the function returns a CSS class name to be deleted.

Example 2:

Copy code The code is as follows:






removeClass() function-Script Home





Script Home welcomes you




Using a function as a parameter, the function returns two CSS class names to be deleted, separated by spaces.

Statement:
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