Getting numeric value of a css property | Sololearn: Learn to code for FREE!
Novo curso! Todo programador deveria aprender IA generativa!
Experimente uma aula grƔtis
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 Respostas
+ 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