Home >Web Front-end >JS Tutorial >How to remove the same level class in Jquery

How to remove the same level class in Jquery

WBOY
WBOYOriginal
2021-11-22 17:32:302424browse

Jquery method to remove the same level class: 1. Use the "$(".Element class name")" statement to obtain the object according to the specified class value; 2. Use the removeClass() method to remove the class of the element , the syntax is "element object.removeClass('element class name')".

How to remove the same level class in Jquery

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

How to remove the same class with Jquery

1. Open the html editor and create a new html file. Find

on the html code page and create a new
in it, and then add a class and text content to this
. The class in the case is: remark.
<div class="remark">今晚要去吃大餐</div>

Create a new click button behind

and add a click event to this button. In the case, the click event is: reClass(), which triggers the removal of the class style when clicked.
<input type="button" value="移除class" onclick="reClass()">

Set class style. Set a style for remark with a font size of 28px and a color of red.

<style>  .remark{   font-size: 28px;color: red;  } </style>

The code is as follows:

How to remove the same level class in Jquery

2. Introduce the jQuery library. Introduce the jquery library after the

<script type="text/javascript" src="jquery.js"></script>

Create a click event. Create a new <script> tag after the <script> tag, and create a click to remove class event in this new tag. </script>

<script type="text/javascript">  function reClass(){   $(".remark").removeClass(&#39;remark&#39;)  } </script>

How to remove the same level class in Jquery

After saving, open it with a browser, click the remove class button, and find that the font size and color in

have been removed, indicating that the class has been removed successfully. . As shown in the picture:

How to remove the same level class in Jquery

How to remove the same level class in Jquery

Related video tutorial recommendations: jQuery video tutorial

The above is the detailed content of How to remove the same level 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