0

Getting numeric value of a css property

suppose I have a css property like below, left: 200px; now, how can I get and use the numeric value(200 in this scenario) of this property in jquery. If I write dom_object.css(“left”); it gives me “200px” rather than 200.

7th Dec 2018, 5:23 PM
rayhan shakil
rayhan shakil - avatar
2 odpowiedzi
+ 1
You can use parseInt() Ex. let padding = parseInt("15px"); //result 15 Taken from : https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/parseInt If parseInt encounters a character that is not a numeral in the specified radix, it ignores it and all succeeding characters and returns the integer value parsed up to that point.
7th Dec 2018, 5:52 PM
Taste
Taste - avatar
0
Thank you very much. It worked :-)
7th Dec 2018, 6:06 PM
rayhan shakil
rayhan shakil - avatar