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.
4 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..
Comments
One way is to use script to dynamically change a CSS rule, e.g.
var image;
if ( /*some condition */ ) {
image = 'a.png';
} else {
image = 'b.png';
}
document.write('<style type="text/css">.someClass {background-image:url("' + image + '");}<\/style>');
Of course there are more sophisticated ways to modify the rule, the above is just a basic method.