-3

I want the height of the texts, not the height of the textarea element. How do I get it with JS, not jQuery?

Highlighed in black

Jasmine Rain
  • 419
  • 2
  • 6
  • 17

2 Answers2

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