Home  >  Article  >  Web Front-end  >  How to add class in jquery

How to add class in jquery

WBOY
WBOYOriginal
2021-12-13 14:41:0516173browse

How to add class in jquery: 1. Use the "$(specified element)" statement to obtain the specified element object; 2. Use the addClass() method to add a class to the specified element. The syntax is "element object.addClass( "new class");".

How to add class in jquery

The operating environment of this tutorial: windows10 system, jquery3.2.1 version, Dell G3 computer.

How to add class in jquery

jquery provides an addClass() method to add a class. You can use this method to class tags Class added. Add a lass class by clicking the button to make the font larger to demonstrate the addClass() method.

addClass() method adds one or more classes to the selected element.

This method does not remove the existing class attribute, but only adds one or more class attributes.

The example is as follows:







This is a heading

This is a paragraph.

This is another paragraph.

Output result:

How to add class in jquery

Related video tutorial recommendation: jQuery video tutorial

The above is the detailed content of How to add class in jquery. 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