Home >Web Front-end >Front-end Q&A >How to set the height of an element in javascript
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.
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: [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!