Home  >  Article  >  Web Front-end  >  How to clear element max-width (maximum width) in jquery

How to clear element max-width (maximum width) in jquery

青灯夜游
青灯夜游Original
2022-04-27 20:03:033356browse

Method to clear max-width: 1. Use css(), syntax "$("specified element").css("max-width","none")"; 2. Use attr() , the syntax is "$("specified element").attr("style","max-width:none;")".

How to clear element max-width (maximum width) in jquery

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

The max-width style of the element

The max-width attribute sets the maximum width of the element.

<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8">
  </head>
  <body>
  	<textarea>文本框默认宽度</textarea><br>
    <textarea style="max-width: 400px;">文本框最大宽度400px</textarea>
  </body>
</html>

How to clear element max-width (maximum width) in jquery

How to clear element max-width (maximum width) in jquery

Method 1 : Use css() to set the value of max-width to none

<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<script src="js/jquery-1.10.2.min.js"></script>
		<script>
			$(document).ready(function() {
				$("button").click(function() {
					$("textarea").css("max-width","none");
				});
			});
		</script>
		<style type="text/css">
			textarea{
				max-width: 300px;
			}
		</style>
	</head>
	<body>
		<textarea>文本框最大宽度300px</textarea><br><br>
		<button>清除max-width</button>

	</body>
</html>

How to clear element max-width (maximum width) in jquery

2. Use attr() to set the value of max-width to none

<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<script src="js/jquery-1.10.2.min.js"></script>
		<script>
			$(document).ready(function() {
				$("button").click(function() {
					$("textarea").attr("style","max-width:none");
				});
			});
		</script>
		<style type="text/css">
			textarea{
				max-width: 300px;
			}
		</style>
	</head>
	<body>
		<textarea>文本框最大宽度300px</textarea><br><br>
		<button>清除max-width</button>

	</body>
</html>

How to clear element max-width (maximum width) in jquery

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

The above is the detailed content of How to clear element max-width (maximum width) in jquery. For more information, please follow other related articles on the PHP Chinese website!

Statement:
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