Saturday, May 25, 2024
 Popular · Latest · Hot · Upcoming
90
rated 0 times [  95] [ 5]  / answers: 1 / hits: 135378  / 15 Years ago, wed, july 8, 2009, 12:00:00

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?


More From » jquery

 Answers
7

This will clean up all non-digits, non-dots, and not-minus-sign from the string:



$(this).css('marginBottom').replace(/[^-d.]/g, '');


UPDATED for negative values


[#99163] Saturday, July 4, 2009, 15 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
travion

Total Points: 137
Total Questions: 96
Total Answers: 103

Location: India
Member since Wed, Aug 4, 2021
3 Years ago
travion questions
Mon, Dec 16, 19, 00:00, 5 Years ago
Sat, Oct 19, 19, 00:00, 5 Years ago
Fri, Sep 20, 19, 00:00, 5 Years ago
Wed, Nov 14, 18, 00:00, 6 Years ago
Sun, Oct 28, 18, 00:00, 6 Years ago
;