membersound
membersound

Reputation: 86747

How to programmatically change the css background image?

I have a GWT.Label with a background gif.

Depending in states I want to change the color and the image of the label. Color change already works, but I don't know how I could change the background image (while still preserving the gradient):

my.css:

/* creates a linear background gradient */
background: #000000;
background: url(myIcon.gif) no-repeat 15px, -webkit-linear-gradient(top, hsla(0,0%,100%,.5), hsla(0,0%,100%,0));
background: url(myIcon.gif) no-repeat 15px, -moz-linear-gradient
background: url(myIcon.gif) no-repeat 15px, -ms-linear-gradient
//etc

Changing the color works:

getElement().getStyle().setProperty("backgroundColor", "green");
//how to change the background image??

How can I alter the image property?

Upvotes: 0

Views: 1147

Answers (1)

Suresh Atta
Suresh Atta

Reputation: 121998

If I am facing that situation,instead of changing properties of css I'l simply change css class

state1

lable.addClassName("state1");// in css with image1

state2

lable.addClassName("state2");//in css with image2

Upvotes: 1

Related Questions