jQuery css()

The jQuery CSS() method is used to get (return)or set style properties or values for selected elements. It facilitates you to get one or more style properties.

jQuery CSS() method provides two ways:

1) Return a CSS property

It is used to get the value of a specified CSS property.

Syntax:

Let's take an example to demonstrate this property.

Test it Now

Output:

This is a heading

The background-color of this paragraph is red.

The background-color of this paragraph is green.

The background-color of this paragraph is blue.

Note: The above example returns the background-color value of the first matched element.

2) Set a CSS property

This property is used to set a specific value for all matched element.

Syntax:

Test it Now

Output:

The background-color of this paragraph is red.

The background-color of this paragraph is green.

The background-color of this paragraph is blue.

3) Set multiple CSS properties

It is just an extension of Set CSS property. It facilitates you to add multiple property values together.

Syntax:

Let's take an example to demonstrate this property. In this example we add two properties background-color and font-size for all element.

Test it Now

Output:

The background-color of this paragraph is red.

The background-color of this paragraph is green.

The background-color of this paragraph is blue.

Next TopicjQuery before()




Latest Courses