New to React and JS, please bear with me if this is obvious.
I have a div element that keeps getting updated with more new content. I need to show the line numbers for that scrollable box of text. I know that I can get the scroll position using scrollTop
and the total height using scrollHeight
, but both of these values are given in pixels.
How do I get the line-height (in pixels) of the text in the div element? I can then use some basic arithmetic to get the line numbers.
Alternately, is there any way to get the scroll position in the unit of line numbers instead of pixels?