Reputation: 4347
on my way to the shortest code on urff.
i have an object, where i make a feature detection. i then pass the result to a jquery.css() command. but i do have some other css rules, that i need to apply, too. i cant put them into the object, cause these rules differ from time to time. so i now pass two jquery.css() commands, but im trying to make one out of it, just for the sexyness..
var myObject = (Modernizr.csstransforms ? {transform: 'translateX(123px)'} : {left: 123});
$("#elem").css(myObject).css({ sexyness: 0 });
while i try to make it something like this:
$("#elem").css(myObject, { sexyness: "100%" });
am i missing something, or is this as good as it gets?
Upvotes: 0
Views: 462
Reputation: 1181
Wrong :( Misread the API
jQuery 1.9 allows you to use arrays of properties, so you can do:
var myObject = (Modernizr.csstransforms ?
["transform: translateX(123px)"] :
["left: 123"]);
$("#elem").css(myObject.add("sexyness: 80"))
Lets cheat and use JSON.parse, which lets us simply concatenate strings
var myObject = (Modernizr.csstransforms ?
'transform: "translateX(123px),"'} :
'left: 123,');
$("#elem").css(JSON.parse(myObject + 'sexyness : 80'))
Upvotes: 0
Reputation: 388316
You can use $.extend() to merge those two css property objects
$("#elem").css($.extend({}, myObject, { sexyness: "100%" }));
Upvotes: 4
Reputation: 1959
You need "glue" objects and use new object for set style. Looks like this:
$.extend(myObject, { sexyness: "100%" });
$("#elem").css(myObject);
Upvotes: 2