For example:
td
has the width set, span
has no width set.
1. Use $.width()
to get the integer width
, $('td').width()
to get the 218px
, span
is 129px
2. Use clientWidth
to get the width without margins and boder
, span
width is 0
, td
width is '218'
3. Use getComputedStyle
to get final width , accurate to the decimal point
, but the width of span
obtained is auto
, td
is 217.5
How to get the exact width of an element with no width set (accurate to the decimal point, displayed in px units
)?
迷茫2017-05-19 10:48:37
<p id="p" style="width:88.88px;"></p>
parseFloat($("#p").attr("style").split('width:')[1])