Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to call CSS from JavaScript

Tags:

javascript

css

I want to have different background images for different conditions (JS,HTML,CSS). For E.g: if(n=1),then image 1 else if(n=2),then image 2 etc.

like image 439
user3598626 Avatar asked Sep 18 '25 00:09

user3598626


1 Answers

Try creating a Css class ..After that you can set it to your control from javascript..

document.getElementById("MyControl").className = "MyClass";

In the css class MyClass you can set the background image..You can create another css class with different background image and set it according to the conditions..

like image 155
Jameem Avatar answered Sep 20 '25 14:09

Jameem