3

Using Jquery, how to I find out if an element is overflowing its container ?

<div style="overflow:hidden"><label>My really really long label</label></div>

I would like to know when the text of the label is being cutoff so that I can act on it.

Thank you

G-Man
  • 7,232
  • 18
  • 72
  • 100

1 Answers1

6

You could use the width function to check if the <label> is longer than the <div>:

if($('label').width() > $('div').width()){
   // longer element 
}

Here's a simple example.

Pat
  • 25,237
  • 6
  • 71
  • 68