Jquery's operations on css are quite convenient, so we can easily modify css through js. Traditional javascript has complicated operations on css, such
<div id="a"
style="background:blue">css</div>
The background syntax is as follows:
document.getElementById("a").style.background
JQuery provides more convenient operations on css:
$("#a").background();$("#a").background(“red”)
Description:
$ ("# A") Get the jQuery object [
<Div id = ""... /Div>
]
$ ("# A"). background () will retrieve the background style of the object.
$ ("# A"). background ("red") sets the background style of this object to redjQuery. The following methods are provided to operate css:
- Background ()
- Background (val)
- Color ()
- Color (val)
- Css (name)
- Css (prop)
- Css (key, value)
- Float ()
- Float (val)
- Height ()
- Height (val)
- Width ()
- Width (val)
- Left ()
- Left (val)
- Overflow ()
- Overflow (val)
- Position ()
- Position (val)
- Top ()
- Top (val)
Here we need to explain css (name); css (prop); css (key,
Value). What do other users know when they look at the name!
<div id="a" style="background:blue;
color:red">css</div><P
id="b">test</P>
Css (name): Get the style named name
$ ("# A" ).css ("color"): red ("# a" ).css ("background
") Will get blue
Css (prop): prop is a hash object used to set a large number of css styles.
$("#b").css({ color: "red", background:
"blue" });
The final result is
<p id="b" style="background:blue;
color:red">test</p>
{Color: "red", background: "blue"
}, Hash object, color is key, "red" is value,
Css (key, value) is used to set a separate css style.
$("#b").css("color","red");
The final result is
<p id="b"
style="color:red">test</p>