Reputation: 13
I have a JavaScript Variable that stores the width of an element ,called popupWidth, in px, e.g. '200px'. The '' are part of the variable, because jQuery needs them. How can I insert the variable into jQuerys .css?
$(this).css({
width: + popupWidth,
});
The code above doesn't work.
Upvotes: 1
Views: 1325
Reputation: 10941
Take a look at the jQuery .css() man page... http://api.jquery.com/css/
It shows that you have to enter the css attributes as essentially a JSON type datastructure... not as just pure text.
$(this).css({ width : popupWidth });
the above should work for you as you have 'already' added the px to the popupWidth variable
Upvotes: 2