How to remove body background image in jquery

青灯夜游
Release: 2022-04-21 15:24:13
Original
2331 people have browsed it

How to remove the body background image: 1. Use css(), the syntax "$("body").css("background","none");"; 2. Use attr(), the syntax "$("body").attr("style","background:none");".

How to remove body background image in jquery

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

Jquery method to remove body background image

Method 1: Use css()

The css() method returns or sets one or more style properties of the matched element.

Use the css() method to directly add a new value "none" to the background attribute and set a new style.

<!DOCTYPE html>
<html>

	<head>
		<meta charset="UTF-8">
		<script src="js/jquery-1.10.2.min.js"></script>
		<style>
			body{
				background: url(img/2.png) no-repeat;
			}
		</style>
		<script type="text/javascript">
			$(document).ready(function() {
				$("button").click(function() {
					$("body").css("background","none");
				});
			});
		</script>
	</head>

	<body>
		<button>去掉body背景图片</button>
	</body>
</html>
Copy after login

How to remove body background image in jquery

Method 2: Use attr()

Use attr() to set the style attribute and add background:none style, overwrites the old style.

<!DOCTYPE html>
<html>

	<head>
		<meta charset="UTF-8">
		<script src="js/jquery-1.10.2.min.js"></script>
		<style>
			body{
				background: url(img/2.png) no-repeat;
			}
		</style>
		<script type="text/javascript">
			$(document).ready(function() {
				$("button").click(function() {
					$("body").attr("style","background:none");
				});
			});
		</script>
	</head>

	<body>
		<button>去掉body背景图片</button>
	</body>
</html>
Copy after login

How to remove body background image in jquery

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

The above is the detailed content of How to remove body background image 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!