Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jQuery .css not recommended in 'production' code

The jQuery documentation makes a remark, ' It's not recommended to use .css() as a setter in production-ready code, but when passing in an object to set CSS, CSS properties will be camelCased instead of using a hyphen.'

a) Why is it not recommended to use this in production-ready code?

b) "but when passing in an object to set CSS, CSS properties will be camelCased instead of using a hyphen."

So jQuery will modify "font-family" to "fontFamily" internally, or is this just a suggestion made here?

Are there any experienced programmers that can further clarify this?

like image 425
Robert Rocha Avatar asked Oct 29 '13 00:10

Robert Rocha


1 Answers

Your answer to point a is found on the same page you linked to:

Using CSS Classes for Styling

As a getter, the .css() method is valuable. However, it should generally be avoided as a setter in production-ready code, because it's generally best to keep presentational information out of JavaScript code. Instead, write CSS rules for classes that describe the various visual states, and then change the class on the element.

like image 78
Jason Sperske Avatar answered Oct 24 '22 15:10

Jason Sperske