jquery appends styles to dom elements, using addClass does not take effect

mistake:

jquery adds a class style to the dom element. Using addClass to add a style will not take effect. Only using css() to add a style will take effect.

$("#id").addClass("checkColor"); does not take effect

Modify to: $("#id").css("background","#0F8100") to take effect

reason:

The issue of style priority. The priority of the parent style is higher than the priority of the later set style, so the style with higher priority will be rendered.

Solution: The priority of the styles in the appended classes should be increased

!important, the function is to increase the application priority (priority) of the specified style rule

As shown below:


.checkColor{
    color: white;
    background: #0F8100!important;
}

 

Guess you like

Origin blog.csdn.net/snowing1997/article/details/125899578