YogeshChauhan . com

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 uninstall Cocoapods from the Mac OS? #4 How to add Read More Read Less Button using JavaScript? #5 How to Use SQL MAX() Function with Dates? #6 PHP Login System using PDO Part 1: Create User Registration Page

Recently Posted

May 7 How to disable right click and drag and drop of images using jQuery? May 7 How to render Lists in React? May 7 What’s the difference between variables in CSS and SCSS (Sass)? May 7 How to define variables in SCSS (Sass)? May 7 How to show and hide an element on click in React? May 5 Use inline if to make a shorter conditional syntax in React

You might also like these

How to make a web page look good on any device?HTMLKilling A Project Part 2: Who should make the decision to kill a project?MiscHow to create rotating texts using JavaScript and CSS?CSSKeyValuePipe in Angular 9AngularIs Software Really Eating The World? I don’t think soMiscCreate dynamic selectors using SCSS (Sass)SCSSHow to add a Bar Chart in Angular App?AngularThe SQL EXISTS OperatorSQL/MySQLPHP Login System using PDO Part 2: Login using Email or UsernamePHPHow to add transparent text on top of an image using CSS?CSSThe flex-grow, flex-shrink and flex-basis Properties in CSSCSSHow to embed YouTube or other video links in WordPress?WordPress