While this may seem like a straightforward question, I'm struggling to find a solution.
Consider a div
with an overflow property set, causing a scroll bar to appear when the text added is larger than its dimensions. You can see an example of this here: http://jsfiddle.net/Lddxgzvz/
My goal is to use vanilla JavaScript to determine the new dimensions of the div with the scroll bar and then use that information to restrict the amount of text that can be added to the div.
Let me explain further...
Suppose the limit for how much can be added to the div is 200px. Once the div
reaches this size, I want the scroll bar to remain static. For instance, if the total width of the following text is 250px:
Hello World Foo Bar
and the word Bar
is 50px wide, only this portion should be visible within the div:
Hello World Foo
I attempted to use JavaScript to retrieve the height and width of the div, but it doesn't account for the overflow property. It simply returns the initial height and width that I set for the div.
I hope my intentions are clear, and I will provide additional edits if needed.