December 7, 2010

Change Unordered list item's color on focus?

Question by Damien Joe

How can we change an unordered list’s item color when it is focused with tab or clicked with mouse using CSS ?

Edit:
Check JSFiddle

Answer by benhowdle89

   .form li input:focus
{
    background-color:yellow;
}

Check that…

If your interested, this jQuery may work, please someone step in and correct it if its wrong!

$(".form li input").click(function(){
        $(this).closest("li").css("background-color","yellow");
});

$(".form li input").blur(function(){
        $(this).closest("li").css("background-color","white");
});

Answer by Starx

Here is your pure CSS solution http://jsfiddle.net/Starx/a93Rb/, only compatible with FF for now. You can make it compatible for the remaining browsers.

Author: Nabin Nepal (Starx)

Hello, I am Nabin Nepal and you can call me Starx. This is my blog where write about my life and my involvements. I am a Software Developer, A Cyclist and a Realist. I hope you will find my blog interesting. Follow me on Google+

...

Please fill the form - I will response as fast as I can!