Home  >  Article  >  Web Front-end  >  How to change css style with jq

How to change css style with jq

醉折花枝作酒筹
醉折花枝作酒筹Original
2021-04-21 13:40:555128browse

In jquery, you can use the css() method to change the style. The syntax format is "$("Element Name").css("Attribute Name", "Attribute Value")"; css() method setting Or return one or more style properties of the selected element, setting the specified CSS property for all matching elements.

How to change css style with jq

The operating environment of this tutorial: windows7 system, javascript version 1.8.5, Dell G3 computer.

Introduce jQuery, and then define the style of the element according to your own element. Here you can casually define the style of the div.

How to change css style with jq

Then we look at the effects brought by the style, and then start setting up interactive effects such as changing colors when clicking the button.

How to change css style with jq

First of all, it is natural to specify the event that triggers the color change, which can be through triggering, etc. Here I will click to trigger the color change.

How to change css style with jq

As shown in the picture, you can use css() to overwrite the style of the original element.

How to change css style with jq

#If you are modifying a single style of an element, separate them with commas. Colons are not allowed.

How to change css style with jq

In this way, you can get the interactive effect, but this is only a change in the effect of one style. How to do multiple effects?

How to change css style with jq

You can wrap multiple styles in curly brackets, separate the styles with commas, and then use colons for the style values, so that they are effective.

How to change css style with jq

Finally, the style interaction is complete, and multiple styles will be modified

How to change css style with jq

[Recommended learning:javascript advanced tutorial

The above is the detailed content of How to change css style with jq. 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