+ 2

How I can get information about margin-X of the object without "px"?

For example, I want to get information about margin top and it will return is n+'px' (ex. "125px"), but I don't need this number with 'px', is it possible?

2nd Apr 2018, 8:05 PM
Фид
Фид - avatar
6 Respuestas
+ 3
you can try with square.offsetTop property of an object or square.getBoundingClientRect()
2nd Apr 2018, 9:13 PM
Damyan Petkov
Damyan Petkov - avatar
+ 2
var n = square.style.marginTop;
2nd Apr 2018, 8:55 PM
Фид
Фид - avatar
+ 2
you can try parseFloat() parseFloat("125px") -> 125
3rd Apr 2018, 8:33 PM
Valérie SPICHER
+ 1
cold you provide some code - how you get margin top ?
2nd Apr 2018, 8:19 PM
Damyan Petkov
Damyan Petkov - avatar
+ 1
okay, thank you
2nd Apr 2018, 9:29 PM
Фид
Фид - avatar
+ 1
Okay
3rd Apr 2018, 8:33 PM
Фид
Фид - avatar