Home >Web Front-end >JS Tutorial >jQuery User Manual (3)_jquery

jQuery User Manual (3)_jquery

WBOY
WBOYOriginal
2016-05-16 18:45:58952browse
Three: CSS operations

Traditional JavaScript’s operation of css is quite cumbersome. For example, the background syntax for
css
is document.getElementById("a" ).style.background, and jQuery is more convenient for css operations, $("#a").background(), $("#a").background("red")
$("#a" ) Get the jQuery object [
]
$("#a").background() will take out the background style of the object.
$("#a").background("red") sets the background style of the object to redjQuery provides the following methods 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)


Need to explain css here (name) css(prop) css(key, value), you will know what the other ones do just by looking at their names!
<div id="a" style="background:blue ; color:red">cssdiv><P id="b">test P>

css(name) Get the style named name
$("#a" ).css("color") will get the color value red in the style, ("#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" });
Final effect It is

test

,{ color: "red", background: "blue" }, hash object, color is the key, " red" is value,

css(key, value) is used to set a separate css style
$("#b").css( "color","red");The final effect is

test

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn