jQuery.css(): marginLeft vs margin-left? Explained

When using jQuery's css() method to get or set the value of an element's margin-left property, you may have noticed that there are two different ways to write it: marginLeft and margin-left. So which one should you use?

The short answer is that they both work the same way. However, using margin-left is considered the more "correct" way, as it follows the standard CSS syntax for hyphenated properties.

That being said, using marginLeft will still work in most cases, as jQuery is smart enough to recognize the camelCase syntax and convert it to hyphenated syntax behind the scenes.

So if you're working on a project where consistency and adherence to standards is a priority, it's recommended to use margin-left when working with the css() method. But if you're more comfortable with camelCase syntax or are working on a project where it's already established as the convention, using marginLeft is still a valid option.

Click to rate this post!
[Total: 0 Average: 0]

Related posts

Leave a Reply

Your email address will not be published. Required fields are marked *

Go up

Below we inform you of the use we make of the data we collect while browsing our pages. You can change your preferences at any time by accessing the link to the Privacy Area that you will find at the bottom of our main page. More Information