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

前端 未结 15 1705
悲哀的现实
悲哀的现实 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:34

    parseInt($(this).css('marginBottom'), 10);
    

    parseInt will automatically ignore the units.

    For example:

    var marginBottom = "10px";
    marginBottom = parseInt(marginBottom, 10);
    alert(marginBottom); // alerts: 10
    

提交回复
热议问题