Yogesh Chauhan's Blog

How to change CSS with jQuery?

in CSS & jQuery on August 23, 2020

We can add, remove or change CSS property values with jQuery just like we can with JavaScript.

Just change it directly.

Easier to target the element than JavaScript.


$('#ID_name').css('padding', '2%');

Change more than one properties


$('#ID_name').css({
 margin: "2%",
 padding: "10px",
 color: "green"
});

Properties with quotes

We can use CSS rules that have hyphens in them (i.e. font-size) OR we can put them in quotes or camel-case the style rule name.


$('.class_name').css({
 "background-color": "blue",
});

Most Read

#1 How to check if radio button is checked or not using JavaScript? #2 How to add Read More Read Less Button using JavaScript? #3 Solution to “TypeError: ‘x’ is not iterable” in Angular 9 #4 How to uninstall Cocoapods from the Mac OS? #5 PHP Login System using PDO Part 1: Create User Registration Page #6 How to Use SQL MAX() Function with Dates?

Recently Posted

#Dec 4 What is Etrieve Flow? #Dec 2 The unique operator($) in Envision Basic #Nov 25 Steps to Install Microsoft SQL Server on a MacOS #Nov 11 What is DevOps? #Nov 10 The * arithmetic operator in Envision Basic #Nov 10 What are Big Data Clusters in SQL Server?
You might also like these
How to create a simple text and image slider using CSS and JavaScript?CSSHow to scroll contents of HTML body horizontally and vertically using JavaScript?JavaScriptHow to concatenate variable with string in Swift?SwiftHow to Draw a Text Image using JavaScript?JavaScriptDid you get an error while displaying Special Characters in JavaScript?JavaScriptFETCH clause in PostgreSQLPostgresEssential SQL Commands We Need to KnowSQL/MySQLHow to create a Recent Posts function in WordPress?WordPressPHP __construct() functionPHPControl rendering using CSS content-visibility propertyCSSHow to link/add CSS file to HTML Document?CSSHow to make a web page look good on any device?HTML