views:

50

answers:

4

Hi, i use the following to to set the text content of an css element

var cell = document.createElement('li');
        cell.textContent = this.labelForIndex(index);

Now i want to set the back-ground image and color.....how to do it??

+3  A: 
$(cell).css("background-image","url('mybg.png)");
SirDemon
thanks a lot...
Rony
@Rony, You may want to improve your accept rate (by accepting a an answer as correct) a bit. Not only for this question, but for all the rest you've asked. Most of us still like the points :)
SirDemon
ok...sorry.....i am new in this site so don't actually know much about it....i tried to put tick mark but i can only tick one..but many developer give me right ans...
Rony
You can only have one accepted answer per question. If you feel one answer is better than the one you've already accepted, you can change your accepted answer.
SirDemon
+2  A: 

Using jQuery:

$(cell).css('background-image', 'url(image-location.jpg)').css('color', '#ABCDEF');
cypher
thanks a lot...
Rony
i use this $(cell).css("background-image", "url(1.gif)");but doesn't work...
Rony
+3  A: 

Use addClass. I think it is less verbose, more efficient, and prettier, plus it is better (i.e. more maintainable) to keep your style definitions outside of your implementation:

.prettyWithImage { background-image: url(/someimage.jpg); color: red }

$(cell).addClass('prettyWithImage');
karim79
+3  A: 

You can use the "map version" of jQuery css method:

$(cell).css({'background-image': 'url("your-bg.png")',
             'background-color': '#abcdef'});

But if you can (if background image and color is always the same for instance) use addClass as karim79 told you to.

p4bl0
@p4bl0: just a thought, but perhaps "...as Karim79 *suggested*..." would sound a little gentler?
David Thomas
@ricebowl: ah, yea. I knew my formulation was a bit rude but nothing else came up to my mind when writing the post, sorry :-).
p4bl0