Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>If the div's size is dependent on the content (which I assume to be the case from your description) then you can retrieve the div's height using:</p> <pre><code>var divHeight = document.getElementById('content').offsetHeight; </code></pre> <p>And divide by the font line height:</p> <pre><code>document.getElementById('content').style.lineHeight; </code></pre> <p>Or to get the line height if it hasn't been explicitly set:</p> <pre><code>var element = document.getElementById('content'); document.defaultView.getComputedStyle(element, null).getPropertyValue("lineHeight"); </code></pre> <p>You will also need to take padding and inter-line spacing into account.</p> <p><strong>EDIT</strong></p> <p>Fully self-contained test, explicitly setting line-height:</p> <p><div class="snippet" data-lang="js" data-hide="false" data-console="false" data-babel="false"> <div class="snippet-code"> <pre class="snippet-code-js lang-js prettyprint-override"><code>function countLines() { var divHeight = document.getElementById('content').offsetHeight var lineHeight = parseInt(document.getElementById('content').style.lineHeight); var lines = divHeight / lineHeight; alert("Lines: " + lines); }</code></pre> <pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;body onload="countLines();"&gt; &lt;div id="content" style="width: 80px; line-height: 20px"&gt; hello how are you? hello how are you? hello how are you? hello how are you? &lt;/div&gt; &lt;/body&gt;</code></pre> </div> </div> </p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload