Jquery User Manual
3.: CSS operations
Traditional JavaScript has complicated operations on CSS. For example, the background Syntax of <Div id = "A" style = "Background: Blue"> CSS </div> is document. getelementbyid (""). style. background, while jquery is more convenient for CSS operations, $ ("# "). background (), $ ("# "). background ("red ")
$ ("# 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 (VAL) CSS (name) CSS (PROP)
CSS (Key, value) float (VAL) height (VAL) width (VAL)
Left () Left (VAL) Overflow (VAL) position (VAL) Top (VAL)
Here we need to explain the CSS (name) CSS (PROP) CSS (Key, value). What do other users know about the functions of their names!
<Div id = "A" style = "Background: Blue; color: Red"> CSS </div> <p id = "B"> test </P>
CSS (name) gets the style named name
$ ("# A" ).css ("color") will get the color value red in the style, ("# A" ).css ("background") will get the 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, and "red" is value,
CSS (Key, value) is used to set a separate CSS style.
$ ("# B" ).css ("color", "Red"); the final effect is <p id = "B"