Home > Web Front-end > JS Tutorial > How to remove css style in jquery

How to remove css style in jquery

藏色散人
Release: 2023-01-04 09:34:14
Original
6303 people have browsed it

Jquery method to remove css styles: 1. Remove css styles by using the "removeClass()" method; 2. Remove a single css style by using the "attr()" method or "css()".

How to remove css style in jquery

The operating environment of this article: Windows 7 system, jquery version 3.2.1, DELL G3 computer

1. Use the removeClass() method to remove the css style

removeClass() method removes one or more classes from the selected element.

Note: If no parameters are specified, this method will remove all classes from the selected elements.

Example: Remove the "intro" class from all

elements:

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<script src="https://cdn.staticfile.org/jquery/1.10.2/jquery.min.js">
</script>
<script>
$(document).ready(function(){
$("button").click(function(){
$("p").removeClass("intro");
});
});
</script>
<style type="text/css">
.intro{
font-size:120%;
color:red;
}
</style>
</head>
<body>
<h1>这是一个标题</h1>
<p class="intro">这是一个段落。</p>
<p class="intro">这是另一个段落。</p>
<button>移除所有P元素的"intro"类</button>
</body>
</html>
Copy after login

2. Use the attr() method or css() to remove a single css style

## The #attr() method can set the attributes and values ​​of the selected element, and can set one or more attribute/value pairs for the matching element.

If you want to use attr() to remove css style, you can set the attribute value to empty.

Example:

$("#show").attr("style","");
Copy after login

css() method can set one or more style attributes of the selected element.

If you want to use css() to remove css style, you can set the attribute value to empty.

Example:

$("#show").css("style","");
Copy after login
Recommended learning: "

jquery video tutorial"

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