-3

I just would like to know if there is a way to check if a div with the overflow hidden attribute can be checked to see if it has content overflowing it or not. Jquery

Amir Ali
  • 417
  • 5
  • 10

1 Answers1

0

Try this....

if (element.offsetHeight < element.scrollHeight ||element.offsetWidth < element.scrollWidth) {
     // your element have overflow
 } else {
  // your element doesn't have overflow
 }

or

if ($("#myoverflowingelement").prop('scrollWidth') > 
 $("#myoverflowingelement").width() ) {
  alert("this element is overflowing !!");  
}
else {
  alert("this element is not overflowing!!"); 
}

refer this link Check with jquery if div has overflowing elements

Avi
  • 1,424
  • 1
  • 11
  • 32
  • this did not work – Amir Ali Aug 16 '18 at 10:39
  • I dont have a scrollheight as I am using overflow is hidden – Amir Ali Aug 16 '18 at 10:40
  • try to give correct id to your element and element name... # means element id – Avi Aug 16 '18 at 10:40
  • Yeah, ive tried that, ive given class name – Amir Ali Aug 16 '18 at 10:44
  • `var invisibleItems = []; for(var i=0; i element.offsetTop + element.offsetHeight || element.children[i].offsetLeft + element.children[i].offsetWidth > element.offsetLeft + element.offsetWidth ){ invisibleItems.push(element.children[i]); } }` – Avi Aug 16 '18 at 10:45
  • Thanks for your help mate, that didn't work too, however I figured how I would do it. I manually calculated it based on the height of the internal div elements – Amir Ali Aug 16 '18 at 10:57