Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Check if scrollbars are present with Javascript?

I'm building a little sticky notes app for fun, and sometimes this happens:

(It's because the first word is wider than the width of the note.)

Is there a way to check whether the scrollbar is present with Javascript? If I can do that, I can resize the note until it contains the text without the scrollbar.


1 Answers

This CSS3 property will break a word within if it is too large for its container:

#selector {  
    word-wrap: break-word;  
}

word-wrap: normal; to toggle style

This works in basically every browser and believe it or not, support for the property goes as far back as IE5. Credit for this goes to Louis Lazaris for his post, Word-Wrap: A CSS3 Property That Works in Every Browser.

like image 66
BumbleB2na Avatar answered Feb 19 '26 00:02

BumbleB2na