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,079
  • 18
  • 68
  • 99

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
  • 24,658
  • 6
  • 71
  • 67