How to add class in jquery
Editor to share with you how to add class in jquery. I hope you will get something after reading this article. Let's discuss it together.
Jquery to add class methods: 1, the use of "$(specified element)" statement to get the specified element object; 2, the use of addClass () method to add class to the specified element, the syntax is "element object .addClass (" new class ");".
The operating environment of this tutorial: windows10 system, jquery3.2.1 version, Dell G3 computer.
Jquery provides a method for addClass () to add the class class, which allows you to add the class class to the tag. Make the font larger by clicking the button to add the lass class to demonstrate the addClass () method.
The addClass () method adds one or more classes to the selected element.
This method does not remove the existing class attribute, but simply adds one or more class attributes.
Examples are as follows:
$(document) .ready (function () {$("button") .click (function () {$("p:first"). AddClass ("intro");});}); .intro {font-size: 40px;} This is a heading
This is a paragraph.
This is another paragraph.
Add a class to the first p element
Output result:
After reading this article, I believe you have a certain understanding of "how to add class in jquery". If you want to know more about it, you are welcome to follow the industry information channel. Thank you for reading!