Convert a value to pixels with JavaScript

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);

Share/Save/Bookmark

,

This post was written by:

rob - who has written 148 posts on Open Source Resources for Designers & Developers | Greepit.com.


Leave a Reply