I want the height of the texts, not the height of the textarea element. How do I get it with JS, not jQuery?
Asked
Active
Viewed 61 times
-3
-
@31piy to dynamically adjust the height of my textarea. – Jasmine Rain Jun 07 '18 at 05:45
-
Please read the post that I've mentioned in the comment, and if it solves the problem, mark your question as duplicate of that. – 31piy Jun 07 '18 at 05:48
2 Answers
0
Use getComputedStyle method
window.getComputedStyle(document.getElementById('idOfElement',null)
.getPropertyValue("height");

brk
- 48,835
- 10
- 56
- 78
-
this actually just gets me the height of the textarea, not the height of the texts – Jasmine Rain Jun 07 '18 at 05:38
-
@JasmineRain if you want to dynamically change the height of the text area according to the text , then set a `min-height` to that text area and `height` to auto – brk Jun 07 '18 at 05:42
0
Try This Code
var element = document.getElementById("elementId");
var size = window.getComputedStyle(element,null).getPropertyValue("font-size");
var fontSize = parseFloat(size.replace('px',''));
var height = (fontSize + 1) + "px";
console.log(height);

Vishal Maru
- 499
- 2
- 8