The difference between. css () and. addclass () Setting styles

Source: Internet
Author: User

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
    1. 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
    2. 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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.