How to get just numeric part of CSS property with jQuery?

前端 未结 15 1694
悲哀的现实
悲哀的现实 2020-11-28 18:53

I need to do a numeric calculation based on CSS properties. However, when I use this to get info:

$(this).css(\'marginBottom\')

it returns

15条回答
  •  暗喜
    暗喜 (楼主)
    2020-11-28 19:37

    parseFloat($(this).css('marginBottom'))
    

    Even if marginBottom defined in em, the value inside of parseFloat above will be in px, as it's a calculated CSS property.

提交回复
热议问题