Anoop
Anoop

Reputation: 242

Javascript error in animate function

When i tried to animate a div , its shows some error on the line shown below.

Here is the code..Is there any syntax error in this

$("#viewport").animate({margin-left:'50px'},"slow");

Thanks in advance.

Upvotes: 0

Views: 86

Answers (2)

Vaibs_Cool
Vaibs_Cool

Reputation: 6156

$("#your_div").animate({marginLeft: '50px'}, 500);

In your case

$("#viewport").animate({'margin-left':'50px'},"slow");

Demo

Upvotes: 0

Brandon Buck
Brandon Buck

Reputation: 7181

You cannot have the - character in Javascript property literals (properties without quotes). jQuery offers a solution for this by converting camelCased names that reference CSS properties to dashed names. So you should change your animate object to {marginLeft: '50px'} or quote the property name like {'margin-left': '50px'}.

Upvotes: 3

Related Questions