1

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.

1 Answer 1

2

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

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.