Reputation: 519
In my website that I am making, I needed to get the scrollLeft value (jQuery, of course) and I needed to get rid of the "px" labeling. So I changed the number into a string and go rid of the "px" labeling like this: var widththis=widther.replace(/[px]/g, "");
So I found out that if I add this number to another, it will appear like this: 1001366
Is there any way to reverse the effect of toString effect? I would love to be able to do this is plain javascript, but jQuery would be fine too. Please also include an example as well if possible.
Thank you in advanced!
Upvotes: 1
Views: 862
Reputation: 85575
You may use like this:
var widththis=widther.replace(/[px]/g, "");
+widththis + anothervar // + prefix added to convert into a number
Upvotes: 1
Reputation: 39268
var number = parseInt('10000', 10);
Try the above
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/parseInt
Upvotes: 0