CSS operations in jQuery User Manual (4)

Source: Internet
Author: User

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>
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.