What is the difference between a addclass and a CSS method for a style setting?
Maintainability:
The essence of the. addclass () is to add one or more classes to an element by defining a style rule for the class. CSS methods are styles that change elements through a lot of JavaScript code
Through. AddClass () We can batch to the same elements set uniform rules, change is more convenient, can be unified to modify the deletion. If you pass the. css () method, you need to specify that each element is a one by one modification, and later maintenance will have to be modified one by one, rather troublesome
Flexibility:
Using the. CSS () method makes it easy to dynamically change the properties of a style without having to go through the tedious definition of a class-class rule. In general, in the uncertain start layout rules, through the dynamically generated HTML code structure, are handled by the. CSS () method.
Style values:
The. addclass () essence is simply an addition to the class of classes that cannot get the value of the property to the specified style, and the. css () can get to the specified style value.
Priority of the style:
CSS styles are prioritized, with the same style rules applied to the same element as the external style, inner style, and inline style, with the following precedence
External style < Inner style < inline style
- The. AddClass () method is done by adding the class name, so the style is defined in the external file or internal style, and is appended to the element when needed
- Inline styles are handled through the. CSS () method, which is appended directly to the element's style property.
Style attributes that are set by the. CSS method are prioritized higher than the. AddClass method
Summarize:
. AddClass and. CSS methods have pros and cons, generally static structure, have determined the layout of the rules, you can use the AddClass method to increase the uniform class rules if it is a dynamic HTML structure, in the case of uncertain rules, or often change, generally consider more. CSS () mode
The difference between. css () and. addclass () Setting styles