AJAX
Basics
Data
DOM
Effects
Events
Forms
jQuery UI
Plug Ins
Traversing
Return a CSS Property
To return the value of a specified CSS property, use the following syntax: css("propertyname");
The following example will return the color value of the element.
Get the font color of demo1:
let colorValue = $("#HelloWorldHeader").css("color");
$("#GetCssButton").click(function () { $("#results").html(colorValue); });
Set a CSS Property
To set the value of a specified CSS property, use the following syntax: css("property name","property value");
$("#SetCSSButton").click(function () { $("#HelloWorldHeader2").css("font-size", "50px"); });
You can also set multiple CSS properties like so:
Notice we use a js object to do this.
$("#SetMultiplePropsButton").click(function ()
{
$("#HelloWorldHeader3").css({
"font-size": "10px",
"font-weight": "bold",
"text-decoration": "underline"
});
});