开发者

How to find the width of the div or check whether horizontal scroll appears or not?

开发者 https://www.devze.com 2023-01-03 23:59 出处:网络
I want to print the page (div) if there is no horizontal scroll appear for that div. I have a div (1000px) with dynamic data which having property overflow:auto;. So, I want to print the div only if d

I want to print the page (div) if there is no horizontal scroll appear for that div. I have a div (1000px) with dynamic data which having property overflow:auto;. So, I want to print the div only if div's width is not getting crossed. to achieve this i used following method of a Javascript

var curr_width = par开发者_运维知识库seInt(mydiv.style.width); 

But it gives 1000px; only although I can see horizontal scrollbar for the div.

What should I do to achieve this?

Can I check whether horizontal scrollbar is appear for the div or not?

Any help is appreciated.

NOTE: I don't want to use any Javascript library.


scrollWidth, clientWidth did the trick

var mydiv = document.getElementById("grid_print");
if (mydiv.scrollWidth > mydiv.clientWidth){
  alert("limit exceeds")
}
0

精彩评论

暂无评论...
验证码 换一张
取 消