How to delete subset class in jquery

青灯夜游
Release: 2022-04-21 18:22:10
Original
2167 people have browsed it

Method to delete subset class: 1. Use find() to get all subset elements under the specified element, the syntax is "specified element object.find("*")"; 2. Use removeAttr() to get all subset elements from To remove class from the obtained subset elements, the syntax is "subset element..removeAttr("class")".

How to delete subset class in jquery

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

jquery deletes a subset of classes

Implementation method:

  • Use find() method Get all subset elements (including subsets of subsets) under the specified element

  • Use the removeAttr() method to remove the specified attribute from the selected element.

    When the parameter of the removeAttr() method is specified as "class", the class can be deleted.

Example:

<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<script src="js/jquery-1.10.2.min.js"></script>
		<style>
			.div,
			div * {
				display: block;
				border: 2px solid lightgrey;
				color: lightgrey;
				padding: 5px;
				margin: 15px;
			}
			.a{
				color: red;
				border: 2px solid red;
			}
			.b{
				color: bisque;
				border: 2px solid bisque;
			}
		</style>

		<script>
			$(document).ready(function() {
				$("button").on("click", function() {
					$("ul").find("*").removeAttr("class");
				});
			});
		</script>
	</head>

	<body class="ancestors">
		<div style="width:500px;">div (父节点)
			<ul>ul (指定元素)
				<li class="a">li (子节点1)
					<span class="b">span (孙节点1)</span>
				</li>
				<li class="a">li (子节点2)
					<span class="b">span (孙节点2)</span>
				</li>
				<li class="a">li (子节点3)
					<span class="b">span (孙节点3)</span>
				</li>
			</ul>
		</div>
		<button>删除子集class</button>
	</body>

</html>
Copy after login

How to delete subset class in jquery

[Recommended learning: jQuery video tutorial, web front-end video

The above is the detailed content of How to delete subset class 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
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!