views:

41

answers:

2

I have a variable which stores the css value of a margin. I want to remove the "px" from the end so that i just have the number to work with. How can i do this?

A: 

Using the String.replace() method is an easy way:

http://www.w3schools.com/jsref/jsref_replace.asp

Rob Olmos
Why the downvote? I can think of several places where parseInt and parseFloat are too picky for general use.
Isaac Lubow
Heh yea, the same user also downvoted the question along with my answer before Alex Reitbort gave his answer. Probably just a malicious user :P
Rob Olmos
+5  A: 
var x = "1px";
var y = parseInt(x);
Alex Reitbort