Convert a value to pixels with JavaScript

Posted by Webber at 6:42 PM


 

I was working on something the other day and needed a quick snippet of JavaScript to convert values to pixels from any string. Below is a quick function:

function px(val) {  return parseInt(val)+"px";  }  }

To use it, just wrap your string with the function and it should convert it to pixels for you:

  var oldValue = '65';  var newValue = px(oldValue);  

Let me know how this works for you and if you make any modifications to improve it. Thanks!

Posted via email from webber's posterous

0 comments: