Home  >  Article  >  Web Front-end  >  How to remove styles in jquery

How to remove styles in jquery

coldplay.xixi
coldplay.xixiOriginal
2020-11-26 11:48:233191browse

Jquery method to remove styles: 1. Use the [removeClass()] method, the code is [removeClass(function(index,class))]; 2. Use the toggleClass method, the code is [toggleClass(class)] .

How to remove styles in jquery

The operating environment of this tutorial: Windows 7 system, jquery version 3.2.1. This method is suitable for all brands of computers.

jquery method to remove styles:

1. removeClass() method

.removeClass([className ])

One or more space-separated style names to remove from each matching element

.removeClass(function(index,class)) :

A function that returns one or more style names to be removed

Note here:

If a style class name is used as a parameter, Only this style class will be removed from the set of matching elements. If no style name is passed as an argument, all style classes will be removed.

jQuery's attributes.toggleClass()

When doing certain effects, you may continuously switch for a certain style of the same node, that is, addClass and Mutually exclusive switching of removeClass, such as the interlaced color changing effect

jQuery provides a toggleClass method to simplify this mutually exclusive logic. The toggleClass method is used to dynamically add and delete Class. One execution is equivalent to addClass, and another execution is equivalent to removeClass

2, toggleClass() method

Adds or removes one or more style classes on each element in the matched element set, depending on the style Whether the class exists or the value switches the property. That is: delete (add) a class

.toggleClass(className) if it exists (does not exist):

on each element in the matched element set One or more (separated by spaces) style class names used to switch

.toggleClass( className, switch )

A Boolean value used for judgment Whether the style should be added or removed

.toggleClass([switch]):

A Boolean value used to determine whether the style class is added or removed:

.toggleClass( function(index, class, switch) [, switch ] ):

is used to return the switch used on each element in the matched element set A function of the style class name. Receives the element's index position and the element's old style class as parameters.

Note here:

toggleClass is a mutually exclusive logic, that is, by judging whether the specified Class name exists on the corresponding element, if so, delete it, if not, add it

toggleClass will retain the original Class name and then add it, separated by spaces.

Related free learning recommendations: javascript (video)

The above is the detailed content of How to remove styles in jquery. For more information, please follow other related articles on the PHP Chinese website!

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