简体   繁体   English

我怎么知道div元素的宽度

[英]how i can know the width of div element

如何获取JavaScript中HTML <div>元素的宽度(以像素为单位)?

try divElement.offsetWidth || divElement.clientWidth 尝试divElement.offsetWidth || divElement.clientWidth divElement.offsetWidth || divElement.clientWidth

and also you might as well want to try divElement.style.width 而且您也可能想尝试divElement.style.width

Note: divElement is the DOM element of your div which can be obtained by document.getElementById("yourDivId") 注意:divElement是div的DOM元素,可以通过document.getElementById("yourDivId")

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何知道用户是否删除了 contenteditable div 中的元素? - How can I know if an user deleted an element in a contenteditable div? 我想知道的宽度 <div> 在我的指令模板中,并存储在变量中我该如何实现 - i want to know the width of the <div> within my directives template ,and store in the variable how can i achieve that 我怎么知道 div 是否在旋转? - How can I know if a div is rotating? 如何根据另一个元素的宽度设置元素的宽度? - How can I set the width of an element based on the width of another element? 如何使用CSS根据上一个div元素的宽度调整文本大小? - How can I have text resize based on the width of the preceding div element using CSS? 如何获得div元素在加载时的宽度以及如何调整其大小? - How can I obtain div element's width on load, and when it's resized? 如何使用jQuery在同一个父元素内动态将“ left” px应用于div的宽度 - How can I dynamically apply the “left” px to a div's width, within the same parent element, using jQuery 如何动态调整DIV元素的宽度以适应其文本内容? - How can I dynamically resize a DIV element's width to fit its text content? 我怎么知道元素是最后一项? - how can I know the element is the last item? 如何设置元素的其余宽度? - How can I set the rest of width to an element?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM