Home > Web Front-end > JS Tutorial > How to add classname to elements in jquery

How to add classname to elements in jquery

WBOY
Release: 2021-11-23 09:34:00
Original
3683 people have browsed it

Jquery method to add classname to an element: 1. Use the "$(element)" statement to match the element object; 2. Use the addClass() method to add a classname to the element. The syntax is "element object.addClass( "classname to add")".

How to add classname to elements in jquery

The operating environment of this tutorial: windows7 system, jquery1.10.0 version, Dell G3 computer.

How to add a classname to an element in jquery

1. Create a new html page, and then add a text with the text

to the html page. and a click event button, and then add a click event to the button.

html code:

<div id="add">点击按钮添加class</div>
<input type="button" value="添加class" onclick="addBtn()" />
Copy after login

Add the style of the class class. Create a