Alex Rivera | Logout

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

Asked 2009-07-08T20:59:11.197
165

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

$(this).css('marginBottom')

it returns the value '10px'. Is there a trick to just getting the number part of the value no matter whether it is px or % or em or whatever?

Edit
Report

1 Answer

128

With the replace method, your css value is a string, and not a number.

This method is more clean, simple, and returns a number :

parseFloat($(this).css('marginBottom'));
answered 2011-02-04T10:05:08.723

Your Answer