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

How to modify z-index value in jquery

青灯夜游
Release: 2021-11-16 15:24:43
Original
3277 people have browsed it

How to modify z-index value in jquery: 1. Use css() method, syntax "$(selector).css("z-index","value")"; 2. Use attr() Method, syntax "$(selector).attr("style","z-index:value")".

How to modify z-index value in jquery

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

In jquery, you can use the css() or attr() method to modify the z-index value of the element.

  • #css() method sets one or more style properties of the selected element.

  • attr() method can set the attribute value of the selected element.

Example:

<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8" />
		<style type="text/css">
			img {
				position: absolute;
				left: 0px;
				top: 0px;
				z-index: -1;
			}
		</style>
		<script src="js/jquery-1.10.2.min.js"></script>
		<script type="text/javascript">
			$(document).ready(function() {
				$("button").click(function() {
					// $("img").css("z-index","1");
					$("img").attr("style","z-index:1;");
				});
			});
		</script>

	</head>

	<body>
		<h1>This is a heading</h1>
		<img  src="img/2.jpg" / alt="How to modify z-index value in jquery" >
		<p>由于图像的 z-index 是 -1,因此它在文本的后面出现。</p><br /><br /><br /><br /><br /><br />
		<button id="but1">改变z-index值,让图片在文字前</button> 
	</body>
</html>
Copy after login

How to modify z-index value in jquery

Related tutorial recommendations: jQuery video tutorial

The above is the detailed content of How to modify z-index value 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!