I am maintaining a project and I am seeing lots of parts that set size values this way:
var position = 500; // This value was calculated in some different way.
$someElement.css({
left: position.toString() + "px"
});
I see that if I change it to
$someElement.css({
left: position
});
it just works fine, but I can't find any documentation regarding older browsers, or some corner cases in which this won't work.
For me, it seems that adding the "px" adds a lot of noise to the code, but I am not sure if it is safe to remove.
I would like to know if there is any case in which this change won't work.
px, but I could be wrong - when I say most, I mean ... all length/position properties that I can think of require a unit of measurementtoStringis totally redundant, justposition + "px"will do. Or are you trying to make it look bad on purpose?