jquery - 查找元素是否溢出其容器

标签 jquery

使用Jquery,如何找出元素是否溢出其容器?

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

我想知道标签的文本何时被截断,以便我可以对其采取行动。

谢谢

最佳答案

您可以使用width function检查 <label> 是否比 <div> 长:

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

这是一个simple example .

关于jquery - 查找元素是否溢出其容器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7717249/

相关文章:

php - html中的ajax,从php中获取结果

javascript - 如何对 id 定义为 php 函数的元素使用 javascript?

javascript - 显示Google柱形图的值

javascript - 指定位置时 jQuery 工具提示在链接上闪烁

javascript - 为 webkit 浏览器优化 javascript 浏览器缩放器

javascript - 在 2 个类之间切换 Jquery

javascript - Bootstrap 弹出窗口样式

jquery - 使用 jQuery 选择器获取一系列表格单元格

javascript - jQuery 快速过滤问题与搜索范围标题属性

jquery - 在几个字符后插入元素