One accepts two input parameters: style attributes and style values, separated by commas. For example we want to change the link color, we can use the following code:
Copy Code code as follows:
$ ("#61dh a"). css (' color ', ' #123456 ');
Here selector ' $ (' #61dh a ') ' represents all links under the element with Id ' #61dh '.
. css (' color ', ' #123456 ') means to set the color to ' #123456 '
If we need to change multiple style attributes, we can first define the property variable and then assign it directly to the CSS () method. Examples are as follows:
Copy Code code as follows:
var divcss = {
Background: ' #EEE ',
Width: ' 478px ',
margin: ' 10px 0 0 ',
padding: ' 5px 10px ',
border: ' 1px solid #CCC '
};
$ ("#result"). CSS (DIVCSS);
Here we first define a CSS style attribute variable ' divcss ', which is similar to creating an external CSS file.
Then through the CSS () method provided by jquery, the attribute is assigned to the DIV with id ' #result '.
In addition, the CSS () method provided by jquery can also be used to view the CSS property values of an element. For example, if we want to see the color of a link, we can use the following code:
Copy Code code as follows:
$ ("#61dh a"). CSS ("color")
Similar to the first example, but here we pass only one argument (style attribute)
The last thing to describe is how to set the link style (for example: color) after the mouse stroke. We can not use the selector directly select the mouse across the state of the link, which means $ ("a:hover") is not established. So we need to use the event class method provided by jquery-hover (). It is worth noting that the hover () method needs to define two functions, one is the mouse is out of date, and the other is after the mouse is drawn. The specific methods are as follows:
Copy Code code as follows:
$ ("#61dh a"). css (' color ', ' #123456 ');
$ ("#61dh a"). Hover (function () {
$ (this). CSS (' color ', ' #999 ');
},
function () {
$ (this). CSS (' color ', ' #123456 ');
});
The two functions of the hover () method are separated by commas
You may have noticed that this method is not concise (contrary to the purpose of jquery),
In fact, jquery provides the hover () method is not used to change the CSS style. In practical use, it is recommended to use the Add/Remove CSS method to change the mouse across the link style.