Home > Web Front-end > Front-end Q&A > How to remove style attribute in jquery

How to remove style attribute in jquery

青灯夜游
Release: 2022-05-16 15:30:14
Original
7208 people have browsed it

In jquery, you can use the removeAttr() method to remove the style attribute. The function of this method is to remove the specified attribute from the selected element. You only need to set the parameter of the method to "style" That's it; the syntax is "$(selector).removeAttr("style")".

How to remove style attribute in jquery

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

The style attribute is the core attribute of HTML and is used to specify inline style for elements. The

style attribute will override other global styles, such as those defined in the

So how to remove the style attribute using jquery

In jquery, you can use the removeAttr() method to remove the style attribute.

removeAttr() method is used to remove attributes from selected elements.

Syntax:

$(selector).removeAttr(attribute)
Copy after login

attribute: required. Specifies the attributes to remove from the specified element.

Example: Remove the style attribute of the first p element

<!DOCTYPE html>
<html>

	<head>
		<meta charset="UTF-8">
		<script src="js/jquery-1.10.2.min.js"></script>
		<script type="text/javascript">
			$(document).ready(function() {
				$("button").click(function() {
					$("p:first").removeAttr("style");
				});
			});
		</script>

	</head>

	<body>
		<h1>这是一个大标题</h1>
		<p style="font-size: 120%;color: blue;background-color: yellow;">这是一个段落。</p>
		<p style="font-size: 120%;color: blue;background-color: yellow;">这是另一个段落。</p>
		<button>移除第一个 p 元素的style属性</button>
	</body>

</html>
Copy after login

How to remove style attribute in jquery

[Recommended learning: jQuery video tutorial, web Front-End Development Video

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