jQuery .css() function not returning expected values

前端 未结 7 1343
情歌与酒
情歌与酒 2020-12-31 08:10

Alright, I\'ve search the jQuery docs (needs somebody devoted to maintaining), I\'ve searched SO, and I\'ve searched Google. I can\'t find the answer to this question.

7条回答
  •  借酒劲吻你
    2020-12-31 08:26

    jQuery always* returns dimensions such as width in units of pixels. Perhaps you can borrow the code from this px to em conversion tool to help you get the value you want.

    It looks like 1.4.2 is the most recent version that will still return $(this).css('width') in its assigned unit of measure, but seemingly only if the width is assigned in the style attribute of the element's tag. If it's in a separate CSS declaration like your example, it comes back as pixels still.

    $(this).width() remains to be in pixels.

    (*in versions 1.4.3 and later)

提交回复
热议问题