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

How to modify the display attribute in jquery

青灯夜游
Release: 2023-01-04 09:59:23
Original
11926 people have browsed it

In jquery, you can use the css() method to modify the display attribute, the syntax "$(selector).css("display","attribute value")" or "$(selector).css({ "display":"Attribute value"})".

How to modify the display attribute in jquery

The operating environment of this tutorial: windows7 system, jquery3.6 version, Dell G3 computer.

In jquery, you can use the css() method to modify the display attribute. The css() method sets one or more style properties of the selected element.

Syntax:

$(selector).css("propertyname","value");
$(selector).css({"propertyname":"value"});
Copy after login

Example: Set the display attribute of the div element to none to hide the div element.

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<script src="js/jquery-3.6.0.min.js"></script>
</script>
<script>
$(document).ready(function(){
	$("button").click(function(){
		$("div").css({"display":"none"});
	});
});
</script>
</head>
<body>

<div style="border: 1px solid red;">hello</div>
<br>
<button>点击按钮,修改display属性</button>

</body>
</html>
Copy after login

How to modify the display attribute in jquery

Recommended related video tutorials: jQuery Tutorial (Video)

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