YogeshChauhan.com
How to change CSS with JavaScript?
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.

dreamhost

Leave a Reply

Most Read

#1 How to check if radio button is checked or not using JavaScript? #2 How to set opacity or transparency using CSS? #3 Pagination in CSS with multiple examples #4 How to make HTML form interactive and using CSS? #5 Solution to “TypeError: ‘x’ is not iterable” in Angular 9 #6 How to uninstall Cocoapods from the Mac OS?

Recently Posted

Mar 5 How to create flickering text using CSS? Mar 4 How to use data-* Attributes in HTML? Mar 4 The substr() method in JavaScript and how it’s different from substring() Mar 4 A complete guide to add responsive YouTube videos using HTML and CSS Mar 3 How to embed YouTube or other video links in WordPress? Mar 3 How to change the Login Logo in WordPress?

You might also like these

SQL Left JoinSQL/MySQLHow to convert datetime to date format in JavaScript?JavaScriptHow to change the Login Logo in WordPress?WordPressHow to Install PHP Laravel in MacOS Catalina?PHPIntroduction to components and templates Part 4: Pipes and DirectivesAngularWhat is the best way to add JavaScript Code into HTML?HTMLHow Do You Make a Private VPN?MiscPostgreSQL BETWEENPostgresOptional arguments, Default parameters and REST parameters in JavaScriptJavaScriptSome interesting HTML Input Attributes to rememberHTMLHow to enable and disable button using JavaScript?JavaScriptCSS Attribute SelectorsCSS