Home>Article>Web Front-end> What to do if jquery addclass doesn’t work

What to do if jquery addclass doesn’t work

藏色散人
藏色散人 Original
2020-12-24 09:50:30 3949browse

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.

What to do if jquery addclass doesn’t work

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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn