Forum Moderators: open

Message Too Old, No Replies

Strip "px" from a variable

         

MartinWeb

10:43 pm on Nov 12, 2009 (gmt 0)

10+ Year Member



What is the easiest way to strip the letters "px" from a variable? Any help would be great.

MartinWeb

10:47 pm on Nov 12, 2009 (gmt 0)

10+ Year Member



I just realized the parseInt works. I'm not sure why. Please ignore this post.

Receptional Andy

10:48 pm on Nov 12, 2009 (gmt 0)



You can use replace()

var str="20px";
document.write(str.replace("px", ""));

MartinWeb

10:54 pm on Nov 12, 2009 (gmt 0)

10+ Year Member



Oh! Thank you. I'll keep that in mind. :)