Home > Web Front-end > JS Tutorial > body text

How to remove class attribute in jquery

青灯夜游
Release: 2021-11-25 10:35:35
Original
6001 people have browsed it

Method: 1. Use attr() to set the value of the class attribute to empty, using the syntax "$(selector).attr("class","")"; 2. Use removeAttr() to remove the class Attribute, syntax "$(selector).removeAttr("class")".

How to remove class attribute in jquery

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

There are two ways to remove the class attribute in jquery:

  • Use attr() to change the value of the class attribute in the element Set to empty

    Syntax:$(selector).attr("class","")

  • Use removeAttr() to remove elements The class attribute in

    Syntax: $(selector).removeAttr("class")

##Example:

<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">

		<script src="js/jquery-1.10.2.min.js"></script>
		<script>
			$(document).ready(function() {
				$("button").click(function() {
					$(".box1").attr("class", "");
					$(".box2").removeAttr("class");
				});
			});
		</script>
		<style>
			div {
				border: 1px solid red;
				margin: 10px;
			}

			.box1 {
				background-color: #FFC0CB;
			}

			.box2 {
				background-color: green;
				color: white;
			}
		</style>
	</head>
	<body>

		<div class="box1">测试文本</div>
		<div class="box2">测试文本</div>
		<br>
		<button>去掉class属性</button>

	</body>
</html>
Copy after login

How to remove class attribute in jquery

Recommended related video tutorials:

jQuery video tutorial

The above is the detailed content of How to remove class attribute in jquery. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template