Home>Article>Web Front-end> What to do if jquery addclass doesn’t work
jquery addclass does not work because the priority of the newly added style is lower than the original style. The solution is to change the changed style writing to ".test .change{background: white;}" That’s it.
The operating environment of this tutorial: windows7 system, jquery1.2.6 version, DELL G3 computer. This method is suitable for all brands of computers.
Recommended:jquery video tutorial
After using jquery’s addClass method, the style has been added successfully, but it still has no effect because the priority of the newly added style is higher than Due to the low original style.
For example, the original style is as follows
.test div{ width: 100px; height: 100px; background: black; }
The changed style is as follows:
.change{ background: white; }
Like this original style with a parent, use it directly for the div in the .test container The addClass("change") statement has no effect because the change style has a lower priority than the original style. You can use the following method:
Change the changed style writing to:
.test .change{ background: white; }
or Change to:
.change{ background: white!important; }
At this time, it will be effective to use the addClass("change") statement on the div in the .test container
The above is the detailed content of What to do if jquery addclass doesn’t work. For more information, please follow other related articles on the PHP Chinese website!