Home >Web Front-end >JS Tutorial >Example of usage of addClass() method in jQuery_jquery
The example in this article describes the usage of the addClass() method in jQuery. Share it with everyone for your reference. The specific analysis is as follows:
This method adds one or more classes to the matching element.
This method has multiple grammatical forms.
Grammar structure 1:
Adds the specified class name to the matching element. If you want to add multiple class names at once, separate them with spaces.
Parameter list:
Example code:
The above code can add two classes to the div, and can set the border and font style of the div.
Grammar structure 2:
Use the return value of the function as the name of the class to be added.
Parameter list:
实例代码:
上面代码和第一个实例的功能是一样的,只不过要添加的类是通过函数返回值得到的。
希望本文所述对大家的jQuery程序设计有所帮助。