1

I try to set the height of a div equalvalent to its width using .width() but I got an error of

Uncaught SyntaxError: missing ) after argument list

here's my js

$('#myDiv').css('height':($('#myDiv').width()));
2
  • You put an extra pair of parentheses around $('#myDiv').width(). Also, the colon in the middle has to be a comma. Commented Oct 15, 2015 at 1:28
  • I want to add. Whenever you see SyntaxError: missing ) after argument list -- This means you either forgot a ) or have too many (s on that line. Cheers Commented Oct 15, 2015 at 1:31

2 Answers 2

6

you have syntax error in your code.

if you want set one item you can use this:

$('#myDiv').css('height',$('#myDiv').width());

if you want to set multiple item you can use this:

$('#myDiv').css({'height':$('#myDiv').width()});

for more info you can check here

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

2 Comments

The first one is used when adding one single property to the CSS. Second one is used when adding multiple CSS properties, separated by commas.
I would recommend adding explanations to this, even if it is minimal.
0

You actually have a pretty normal error. All you have to do is reformat your code to:

$('#myDiv').css('height',$('#myDiv').width());

Just remove the colon and extra parentheses!

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.