How can we change propertyName/s with ternary operators?
For example:
var horizontal = false,
propertyName = horizontal ? 'left' : 'top';
$(".elem").css({
propertyName: value
});
I've found some answers, but they do not fit to my circumstances.
https://stackoverflow.com/a/5973518/1250044
https://stackoverflow.com/a/12228404/1250044
Praveen Kumar has found a possibility. But yet still no final!
OK, I think the best answer is, as Explosion Pills Explosion Pills said:
var horizontal = false;
$(".elem").css(horizontal ? {
left: 10
} : {
top: 10
});
Live as Fiddle.