Danish Adeel Danish Adeel - 1 year ago 78
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 ?

Answer Source

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

prop = lang == 'ar' ? 'right' : 'left';
$('#head').css(prop, "200");
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download