Use jquery to determine whether an element contains a specified class instance, jqueryclass

Source: Internet
Author: User

Use jquery to determine whether an element contains a specified class instance, jqueryclass

In jquery, two methods can be used to determine whether an element contains a definite class ). The two methods have the same functions.

The two methods are as follows:

1. is ('. classname ')

2. hasClass ('classname ')

The following is an example of whether a div element contains a redColor:

1. Use the is ('. classname') Method

$ ('Div '). is ('. redcolor ')

2. Use the hasClass ('classname') method (note that the earlier version of jquery may be hasClass ('. classname '))

$ ('Div '). hasClass ('redcolor') The following is an example of checking whether an element contains a redColor class. If the element contains a redColor class, the class is changed to blueColor.

<!DOCTYPE html>

In this article, jquery is used to determine whether an element contains a specified class instance. This is all the content shared by Alibaba Cloud. I hope to give you a reference, we also hope that you can support the customer's home.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.