It is possible to use a variable as a value:
$("#anything").css({
"top": value
});
But if I try the opposite:
toporbottom = "top";
$("anything").css({
toporbottom: "50px"
});
it doesnt work. Is there a elegant solution?
In your case, you don't need an object because you're only setting one property. Use:
$(...).css(toporbottom, "50px");
If you do want an object, you'll have to make an empty one first, then set the property using the [...] notation, and pass obj. But this is definitely overkill here:
var obj = {};
obj[toporbottom] = "50px"; // `obj["top"]` is the same as `obj.top`
$(...).css(obj);