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
How to add MySQL alternate port and sockets/pipes in WordPress?WordPressClean Form Input With These PHP Functions Before Inserting into DatabasePHPfirst-of-type and last-of-type selectors in CSSCSSWhat are “holes” in a React component?ReactHow to modify AutoSave Interval using code in WordPress?WordPressWhat are CSS Specificity Rules and how does browser apply them?CSSColleague UI Basics: Accessing the user interfaceColleagueHow to set opacity or transparency using CSS?CSSCreate a galley with overlapping images using CSS gridCSSRendering Elements in ReactReactHow to select multiple values in React dropdown?ReactHow to overwrite file contents with new content in PHP?PHP