JQuery CSS () method to change the existing CSS style sheet, jquerycss
The CSS () method is used to change the existing CSS style sheet. The css () method is diverse in usage. There is one type that can accept two input parameters: style attributes and style values, which are separated by commas. For example, to change the link color, you can write the code as follows:
$ ("# 61dh a" ).css ('color', '#123456'); // selector '$ ("# 61dh ") 'indicates all links under the element whose ID is' # 61dh. //. Css ('color', '#123456'); sets the color to '#123456'
If you need to change multiple style attributes, You can first define the attribute variables and then assign them directly to the css () method.
var mycss = {background: '#EEE',width: '478px',margin: '10px 0 0',padding: '5px 10px',border: '1px solid #CCC'};$("#result").css(divcss);
The above code first defines a CSS style attribute variable "mycss", similar to creating an external CSS file, and then using the css () method, assign the property to the DIV with ID '# result.
In addition, the css () method provided by jQuery can also view the css attribute values of an element. (Www.jbxue.com script School)
For example, to view the link color, the Code is as follows:
$("#61dh a").css("color")
You will find that this is similar to the first example, but only one parameter (style attribute) is passed here ).
The last section describes how to set the link style (for example, color) after the mouse is crossed. You need to use the jQuery event class method-hover (). It is worth noting that the hover () method needs to define two functions, one is mouse stroke, and the other is behind the mouse. The specific method is as follows:
$ ("# 61dh a" ).css ('color', '#123456'); $ ("# 61dh a" watermark ('color ', '#123456') ;}); // use commas to separate the two functions of the hover () method.
Maybe you have noticed that this method is not concise. In fact, the jQuery hover () method is not used to change the CSS style. In practical use, we recommend that you use the Add/remove CSS method to change the style of the link over the mouse.
How does jquery change the css style?
Add the following section in html:
<Script type = "text/javascript" src = "ajax.googleapis.com/ajax/libs
/Jquery/1.4.0/jquery. min. js "> </script>
<Script type = "text/javascript">
$ (Function (){
$ (". Home"). click (function (){
$ (This). addClass ("home_hover"). removeClass ("home ");
})
})
</Script>
How can I use JS to change the style of the loaded CSS style sheet? Detailed tutorial
I have already said this, but it is simpler to use jquery. For example, to change the class to the undis style
$ (". Undis" ).css ("margin-left", "30px ");
Or add a class for it.
$ (". Undis"). addcss ("dis ~
This advantage is that css styles are the same. if Javascript is used, css styles are written differently. For example, margin-left. In js, marginleft must be written.