Official JQuery learning materials: CSS

Source: Internet
Author: User

// Obtain CSS attributes$ ("H1" ).css ("fontSize"); // returns a string, for example, "19px"$ ("H1" ).css ("font-size"); // This is also possible// Set CSS attributes$ ("H1" ).css ("fontSize", "100px"); // you can specify an attribute.// Set multiple attributes$ ("H1" ).css ({FontSize: "100px ",Color: "red"});

 

  • Use Class
Var $ h1 = $("h1 ");$ H1.addClass ("big"); // Add a class$ H1.removeClass ("big"); // remove class$ H1.toggleClass ("big"); // switch the class to determine whether to add or remove the class based on the existence of the class and the second parameter.If ($ h1.hasClass ("big ")){// Determine whether the class contains "big "}

Class is also very useful and can store the status information of elements, such as whether the elements are selected.

 

  • Dimensions
// Set the width of all elements$ ("H1"). width ("50px ");// Obtain the width of the first element$ ("H1"). width ();// Set the height of all elements$ ("H1"). height ("50px ");// Obtain the height of the first element$ ("H1"). height ();// Return the location information of an object containing the first element, which is offset from the parent node.$ ("H1"). position ();

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.