I want to know if this is possible using JavaScript. I want to extract, say third line, from the following page:
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Vestibulum felis elit, scelerisque id rhoncus et, hendrerit nec turpis. Phasellus eget condimentum justo. Aliquam porta, risus sed elementum hendrerit, turpis urna posuere libero, eget facilisis sem purus sed mi. Nulla pulvinar nibh quis bibendum lacinia. Aenean eu nibh pharetra, imperdiet mi eget, vehicula mauris. In hac habitasse platea dictumst. Phasellus ante enim, bibendum quis turpis a, volutpat auctor mi. Mauris scelerisque sem a ornare dignissim. Nullam in sem ac turpis aliquet dictum sit amet dignissim est.</p>
I believe my html looks like:
And the red underlined line is the third line, which is adjusted dynamically in the view.
I tried .innerHTML and .innerText method, but it fails to identify the line breaks.
I thought if I can somehow get the scrollHeight of each lines and then use JavaScript, but I didn't found any supporting methods on internet. Any ideas?
Note: One can assume that he/she has access to the
pelement. We may proceed with a client-side JS/HTML solution.
