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 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 tab interaction using CSS?CSSWHERE Clause in PostgresPostgresUseful (and probably ignored) HTML tags: Part 1HTMLHow to create a for loop in SCSS (Sass)?SCSSHow to use @supports rule in CSS?CSSWhat happens when we add Numbers and Strings in JavaScript?JavaScriptGlobal JavaScript methods to convert variables to numbersJavaScriptList of all Pseudo Elements in CSSCSSHow to add Go Back button in Swift 5?SwiftHow to make a curtain slider using jQuery and CSS?CSSLIMIT and OFFSET in PostgresPostgresHow to create a vertically rotating texts using CSS?CSS