Why are you making a JSON string and then parsing it, instead of just making a JS object?
This is what you should be doing, unless I'm misunderstanding:
var style = {};
style[attrName] = $(this).val();
eleContainer.css(style);
Or if you're truly just setting one CSS attribute, you could do as @Nick suggested, like this:
eleContainer.css(attrName, $(this).val());
BTW, if that's your actual code, you would probably be getting errors since you're missing the +
concatenator.
UPDATE:
.css()
is a one-time setting for the set of matched elements. It does not create a permanent CSS rule that applies to elements that don't yet exist.
If you want to actually create a CSS rule instead of applying certain CSS styles to a set of specific elements, then you could dynamically create a <style>
tag:
$("<style> .container { "+ attrName +": '"+ $(this).val() +"'; } </style>")
.appendTo('body');
See also: Create a CSS rule / class with jQuery at runtime