Danish Adeel Danish Adeel - 5 months ago 13
CSS Question

Jquery: Can we use variable in css property?

I have a multi language website, I wanna change my container position according to language. For this I have to change its position accordingly I tried below code.

prop = lang == 'ar' ? 'right' : 'left';
$('#head').css({ prop : 200 });

But I am unable to achieve this, when I put static property then its working. I know there are other ways but Is it not possible like this ?


You are using the version of css that required named properties. Use the other version.

prop = lang == 'ar' ? 'right' : 'left';
$('#head').css(prop, "200");