jQuery / Javascript - How do I convert a pixel value (20px) to a number value (20)
No jQuery required for this, Plain Ol' JS (tm) will do ya,
parseInt(a, 10);
More generally, parseFloat
will process floating-point numbers correctly, whereas parseInt
may silently lose significant digits:
parseFloat('20.954544px')
> 20.954544
parseInt('20.954544px')
> 20
var c = parseInt(a,10);