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
1 Answer
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
6 Comments
Amir Ali
this did not work
Amir Ali
I dont have a scrollheight as I am using overflow is hidden
Avi
try to give correct id to your element and element name... # means element id
Amir Ali
Yeah, ive tried that, ive given class name
Avi
var invisibleItems = []; for(var i=0; i<element.childElementCount; i++){ if (element.children[i].offsetTop + element.children[i].offsetHeight > element.offsetTop + element.offsetHeight || element.children[i].offsetLeft + element.children[i].offsetWidth > element.offsetLeft + element.offsetWidth ){ invisibleItems.push(element.children[i]); } } |