Introduction
We web developers sometimes need to apply styles that have not been defined in a stylesheet or inline. For this jQuery offers the .css() method for such occasions. The .css method acts as a getter and setter. To get the style property, we simply pass the name of the property as a string like .css('fontSize') and to set the style property; the .css() method provides two different ways:
Way 1: Single Property
.css('fontSize','14px')
Way 2: Multiple Properties
.css({
'property1': 'value1',
'property-2': 'value2'
})
Let's have a HTML Content that will consume this service.
<body>
<h1>Font Size Controller</h1>
<div id="fontController">
<button id="fontController-large">Bigger</button>
<button id="fontController-small">Smaller</button>
</div>
<div class="aboutVS">
<p>
Microsoft Visual Studio is an integrated development environment (IDE) from Microsoft.
It is used to develop console and graphical user interface applications along with Windows
Forms applications, web sites, web applications, and web services in both native code together
with managed code for all platforms supported by Microsoft Windows, Windows Mobile, Windows CE,
.NET Framework, .NET Compact Framework and Microsoft Silverlight.
</p>
</div>
</body>
In the above HTML markup, I have two different DIVs inside the <body> tag; the first one is 'fontController' and the second one is "aboutVS". Inside the "fontController" DIV, I have two HTML buttons to increase and decrease the font size.
Now let's create jQuery methods that will apply the font increase/decrease functionality to "aboutVS" named DIV when the user clicks the button.


Join the conversation! Your thoughts help the community grow.