Home > Article > Web Front-end > How to change css style with jq
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.
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.
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.
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.
As shown in the picture, you can use css() to overwrite the style of the original element.
#If you are modifying a single style of an element, separate them with commas. Colons are not allowed.
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?
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.
Finally, the style interaction is complete, and multiple styles will be modified
[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!