JQuery Attribute-addClass () method, jquery-addclass

Source: Internet
Author: User

JQuery Attribute-addClass () method, jquery-addclass

1. General Definition and usage

Syntax

$(selector).addClass(class)
Parameters Description
Class Required. Specify one or more class names.

 

 

 

2. Add a class to a function: Use a function to add a class to the selected element.

Syntax

$(selector).addClass(function(index,oldclass)
Parameters Description
Function (index, oldclass) Required. Specify to return one or more functions with the class name to be added.
  • Index-optional. The index position of the selector.
  • Class-optional. The old class name of the selector.

 

 

 

 

Common Definition usage

 

<Html> <P> Hello kayze-refresh </p>
<P> Hello kayze-refresh </p> <button> Add a class to the first p element </button> </body>

 

 

Function addition class usage

1. function (index)

Index-optional. The index position of the selector.

<!DOCTYPE html>

 

2. function (index, oldclass)

Index-optional. The index position of the selector.
Class-optional. The old class name of the selector.

When the target element of the class needs to be added to the class, the elements containing the class are

When this method is used, the function of the class name is added only when the target element contains the oldClass class name.

<!DOCTYPE html>

 

I am a cainiao. If you have any other ideas, please leave a message to me and I will learn how to modify it.

Not complete to be continued!

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.