views:

49

answers:

2

I am setting background color of an li element by the code below :

$('#li123').animate({ backgroundColor:  color}, 'slow');

It works fine but the color spans whole length of li. What do I do if I want it to span the text contained in the li only.

+2  A: 

Wrap the text inside the li in a span and do the animate on the span instead. If you need top and bottom margin of the animated area you could use display: inline-block on the span.

anddoutoi
That worked fine. Can you tell me how bold the text also?
fastcodejava
`fontWeight: bold` perhaps?
anddoutoi
I thought so too, but it doesn't.
fastcodejava
add css attribute `font-weight: bold;`
The Elite Gentleman
A: 

Simple,

For your <li> add a <span>, enter your text in the span block and do a JQuery animate on that span. Your question isn't too clear though.

The Elite Gentleman
But I want to color the background.
fastcodejava
Did you actually downvote him for this answer?
Younes
Downvote removed after the edit.
fastcodejava