Home > Web Front-end > JS Tutorial > body text

jquery method to determine whether class exists

藏色散人
Release: 2021-01-21 17:42:23
Original
8228 people have browsed it

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')
Copy after login

2. Method of using hasClass('classname')

$('div').hasClass('redColor')
Copy after login

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!

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
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!