cmac cmac - 5 months ago 16
CSS Question

Does jQuery .css() method add the 'px' for you on top, right, bottom, left properties if you give it an integer?

Does jQuery add the +'px' for me?

position: absolute;
top: 23,
right: 24,
left: 25,
bottom: 26

So I don't have to do this:

position: absolute;
top: 23 +'px',
right: 24 +'px',
left: 25 +'px',
bottom: 26 +'px'

It seems to work the first way, but if I try to do it like that in css file:


It doesn't work. I just want to be sure jquery is adding it and it's not some browser indifference or something.


Yes, it does. jQuery assumes, and adds, .px if no unit is given.

As you've discovered, this does not happen in native CSS, where a unit is required for non-zero numerical property values.