Yogesh Chauhan's Blog

How to change CSS with JavaScript?

in CSS & JavaScript on August 23, 2020

We can add, remove or change CSS property values with JavaScript via an element's style property.

Step 1

Get the element via ID or class.

var element = document.getElementById("ID_Name");

Step 2

Change the CSS property.

element.style.opacity = 1;
element.style.fontFamily = 'sans-serif';

The property name changes (not completely!) when we use JavaScript. So, font-family becomes fontFamily.


Most Read

#1 How to check if radio button is checked or not using JavaScript? #2 Solution to “TypeError: ‘x’ is not iterable” in Angular 9 #3 How to add Read More Read Less Button using JavaScript? #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

#Aug 2 How to progressively load images and add a blurry placeholder? #Aug 1 How to create a placeholder loader (throbber) using CSS? #Aug 1 What is Zdog? #Aug 1 How to add before after image effect using pure CSS? #Jul 31 Add animation to your skills bar using CSS #Jul 31 Use SwiperJS to create mobile touch sliders fast
You might also like these
What is Git?MiscellaneousVariables and Distance Functions in SCSS (Sass)SCSSWhere is the PHP log file located on Mac OS?PHPSafe Practice to add Links to cross-origin destinationUI/UXHow to insert Bootstrap 4 in Angular 9 app?AngularHow to show confirmation alerts with OK and cancel buttons using Swift 5?SwiftHow to create a smooth scrolling effect with CSS?CSSKilling A Project Part 4: What Would Be Your Top 3 Priorities For Planning The Cancellation?MiscellaneousHow to Make CSS Lists Bullets Smaller?CSSSelector Lists and Combinators in SCSS (Sass)SCSSIntroduction to components and templates Part 4: Pipes and DirectivesAngularHow to retrieve homepage URL in WordPress?WordPress