Home >Web Front-end >JS Tutorial >jquery method to determine whether class exists

jquery method to determine whether class exists

藏色散人
藏色散人Original
2020-12-14 10:36:568287browse

Jquery method to determine whether a class exists: 1. Use the "is('.classname')" method to determine whether a class exists; 2. Use the "hasClass('classname')" method to determine whether a class exists.

jquery method to determine whether class exists

The operating environment of this tutorial: windows7 system, jquery1.10.0 version, thinkpad t480 computer.

Recommended: "jquery video tutorial"

jquery determines whether a class exists

The two methods are as follows:

● hasClass('classname')

● is('.classname')

Example:

1. Use is('.classname') method

$('div').is('.redColor')

2. Method of using hasClass('classname')

$('div').hasClass('redColor')

Extended information:

Introduction to jquery's hasclass() and is() that appear above

1, is()

is(expr|obj|ele|fn)

Detect the set of matching elements based on the selector, DOM element or jQuery object, if at least Returns true if an element matches the given expression.

If no element matches, or the expression is invalid, 'false' is returned. '''Note:''''Support for all expressions is only available in jQuery 1.3. In previous versions, if complex expressions, such as hierarchical selectors (for example, ~ and > ), were provided, they would always return true

2. hasclass()

checks the current Whether the element contains a specific class, if so, returns true.

This is actually is("." class).

Description: Perform an animation on an element containing a certain class.

The above is the detailed content of jquery method to determine whether class exists. 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