Open In App

jQuery css() Method

Last Updated : 07 Jul, 2023
Comments
Improve
Suggest changes
3 Likes
Like
Report

The css() method in jQuery is used to change the style property of the selected element. This method can be used in different ways. The css() method can be used to get/return the present value of the property for the selected element.

Syntax:

$(selector).css(property)

or

$(selector).css(property, value)

or

$(selector).css(property, function(index, currentvalue))

or

$(selector).css({property:value, property:value, ...})

Return value: It will return the value of the property for the selected element. 

Example 1: In this example, we will use css() method to get the text color of the paragraph element.

Output: 

Example 2: In this example, we will use css() method to change the CSS style of the selected element.

Output: 

 

Example 3: In this example, we will use css() method to add styles using the function.

Output: 

Example 4: In this example, we will use css() method to apply multiple CSS properties simultaneously.

Output:


Next Article

Similar Reads