// 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"}); |
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.
// 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 (); |