开发者

width of copy inside an element

开发者 https://www.devze.com 2023-01-23 19:53 出处:网络
How can I find the width of an element in JavaScript/jQuery without counting the part that is trailing whitespace.The result for the example below would be 16px because it is only one character, and t

How can I find the width of an element in JavaScript/jQuery without counting the part that is trailing whitespace. The result for the example below would be 16px because it is only one character, and the font size is 16px.

<div class="styled" 
     style="width: 1024px; margin: 5px; border: 10开发者_如何学运维0px solid lemonchiffon;">
0
​</div>


$("#whateverYourDivIs").children().width() ?

Since you want to get at only the text, get the computed width of the text node inside the div

0

精彩评论

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