$(selecor).css(name)
The css() method returns or sets one or more style properties of the matched element.
Set the color of the <p> element:
- $(".button").click(function(){
- $("p").css("color","blue");
- });
Use functions to set css properties
- $(selector).css(name,function(index,value))
- //index is the index position of the element in the object collection, and value is the original attribute value.
For example, set the color of all paragraphs to red
- $("button").click(function(){
- $("p").css("color",function(){return "red";});
- });
Gradually increase the width of the div
- $("div").click(function() {
- $(this).css(
- "width", function(index, value) {return parseFloat(value) * 1.2;}
- );
- });
set multiple css properties
- $(selector).css({property:value, property:value, ...})
E.g
- $("button").click(function(){
- $("p").css({
- "color":"white",
- "background-color":"#98bf21",
- "font-family":"Arial",
- "font-size":"40px",
- "padding":"5px"
- });
- });
- });
jQuery width(),height()
The width() method sets or returns the width of the element (excluding padding, borders, or margins).
The height() method sets or returns the height of the element (excluding padding, borders, or margins).
- $("button").click(function(){
- var txt="";
- txt+="Width: " + $("#div1").width() + "</br>";
- txt+="Height: " + $("#div1").height();
- $("#div1").html(txt);
- });
body{ “background-color” :snow; }