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

 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.

 "background-color": "blue",

Most Read

#1 Solution to the error “Visual Studio Code can’t be opened because Apple cannot check it for malicious software” #2 How to add Read More Read Less Button using JavaScript? #3 How to check if radio button is checked or not using JavaScript? #4 Solution to “TypeError: ‘x’ is not iterable” in Angular 9 #5 How to uninstall Cocoapods from the Mac OS? #6 PHP Login System using PDO Part 1: Create User Registration Page

Recently Posted

#Apr 8 JSON.stringify() in JavaScript #Apr 7 Middleware in NextJS #Jan 17 4 advanced ways to search Colleague #Jan 16 Colleague UI Basics: The Search Area #Jan 16 Colleague UI Basics: The Context Area #Jan 16 Colleague UI Basics: Accessing the user interface
You might also like these
Recursive WITH Queries in Postgres (Common Table Expressions)Postgres4 different Ways to Get JavaScript OutputJavaScriptHow to add navigation menu in Angular 9 app?AngularHow to install Gulp with WordPress?WordPressHow to position an image on top of another image using CSS?CSSHow to remove trailing characters from a string using JavaScript?JavaScriptWhat is HTMLUnknownElement?HTMLHow to overwrite file contents with new content in PHP?PHP@forward modules with a prefix in SCSS (Sass)SCSSCanvas Drawing in HTML5HTMLHow to make a curtain slider using jQuery and CSS?CSS5 Steps to Create a Line using Canvas Tag in HTML5HTML