Easy Tutorial
❮ Jq Event Type Eff Hide ❯

jQuery css() Method

jQuery HTML/CSS Methods

Example

Set the color property for all <p> elements:

$("button").click(function(){
    $("p").css("color","red");
});

Definition and Usage

The css() method sets or returns one or more style properties for the selected elements.

When used to return a property: This method returns the specified CSS property value of the first matched element.

When used to set properties:


Syntax

Return a CSS property value:

Set a CSS property and value:

Set a CSS property and value using a function:

Set multiple properties and values:

Parameter Description
property Specifies the CSS property name, such as "color", "font-weight", etc.
value Specifies the value of the CSS property, such as "red", "bold", etc. <br>
function(index, currentvalue) Specifies a function that returns the new value of the CSS property. index - Returns the index position of the element in the set.<br> <br>currentvalue - Returns the current value of the CSS property.

More Examples

Return a CSS Property Value

Set a CSS Property and Value Using a Function

Set Multiple CSS Properties and Value Pairs


jQuery HTML/CSS Methods

❮ Jq Event Type Eff Hide ❯