Home >Web Front-end >Front-end Q&A >How to set the height of an element in javascript

How to set the height of an element in javascript

青灯夜游
青灯夜游Original
2021-09-16 15:31:5810675browse

Setting method: 1. Use the "document.getElementById("id value")" statement to obtain the specified element object; 2. Use "element object.style.height="value"" or "element object.style" .cssText="height:value"" statement to set.

How to set the height of an element in javascript

The operating environment of this tutorial: windows7 system, javascript version 1.8.5, Dell G3 computer.

javascript sets the height of the element

1. Get the element object

document.getElementById("id值")

2. Set the height of the element

  • Use object.style.property name="value"

  • UsingObject.style.cssText="Attribute name:value"

##Example

<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8">
  </head>
  <body>
  	<textarea>文本框默认宽度</textarea><br>
    <textarea id="text1">文本框高度设置为50px</textarea><br>
	<textarea id="text2">文本框高度设置为100px</textarea>
	<script type="text/javascript">
		document.getElementById("text1").style.height="50px";
		document.getElementById("text2").style.cssText="height:100px";
	</script>
  </body>
</html>

Rendering:

How to set the height of an element in javascript

[Recommended learning:

javascript advanced tutorial]

The above is the detailed content of How to set the height of an element in javascript. 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