I currently have a contentEditable div with a fixed width and a flexible height, which should be increased or decreased according to the length of the user input.
The problem is that in the following code, I get the contentEditable height based on the last char, this is my code:
<!-- THE JS FUNCTION THE GETS THE DIV CALLED title HEIGHT--> function setInTitle() { var titleHeight = document.getElementById('title').offsetHeight; } <!-- THE DIV CALLED title --> <div id="title" class="title" contenteditable="true" style="font-family: Helvetica; font-size:18px; font-weight:bold; background-color:#fff; color:#000; -webkit-tap-highlight-color:rgba(0,0,0,0); margin:14px;" autocapitalization="off" autocorrection="off" autocomplete="off" onKeyPress="setInTitle();" <==CALL THE JS FUNCTION ></div>
So, I need through JAVASCRIPT to immediately get the height of the contentEditable after the new char is introduced, and, if possible, before the char is displayed, for example, the diagram below:
KEYBOARD KEYBOARD =>
JS GET HEIGHT OF CONTENT INTERACTION WITH NEW char =>
CHAR NOW turns out (This is just a simulation, of course, things will not look strictly like that)
It can be done? Any ideas would be appreciated, thanks in advance!
source share