开发者

width of copy inside an element

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜