| <! DOCTYPE html PUBLIC "-// W3C // dtd xhtml 1.0 Transitional // EN" Http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd> <Html xmlns = "http://www.w3.org/1999/xhtml"> <Head> <Meta http-equiv = "Content-Type" content = "text/html; charset = UTF-8"/> <Title> Jquery css method </title> <Style type = "text/css"> Div {width: 100px; margin: 0px auto; border: 1px solid red ;} </Style> <Script src = "jquery-1.6.2.min.js" type = "text/javascript"> </script> <Script type = "text/javascript"> $ (Function (){ $ ("# BtnChangeCss"). click (function (){ Var $ divs = $ ("div"); // returns the JQuery object, which contains two div elements. // ---- Example 1 // Alert ("Div Border style:" + divs.css ("border-color ")); // Read the css style // ---- Example 2 // Define divs.css ("backgroundColor", "# ccff66 "); // Set the background color of two div elements // ---- Example 3 set three css attributes in a chain $Divs.css ("width", "500px" ).css ("background-color", "# ffff00" ).css ("font-size", "88px "); }); }); </Script> </Head> <Body> <Input id = "btnChangeCss" type = "button" value = "Change style"/> <Div id = "div1"> I am div1 </div> <Div id = "div2"> I am div2 </div> </Body> </Html> |