Skip to content

Adding background color on hover and not hover

January 6, 2016
 To hover or not to hover…To follow up on the theme on JQuery and on hover on ul li.items, here as promised is a quick and efficient way of adding background color to a ul li item on hover and unhover essentially within the same function, you simply embed one function into another like so:-
        $(‘ul.categorylist li:nth-child(1)’).addClass(“active”);
        $(‘ul.orderitems li’).hover(function (e) {
            $(this).css(‘background-color’, ‘lightgrey’);
        }, function(){
            $(this).css(‘background-color’, ‘white’);
        });
   
So the second function essentially is the false component of the first function on the hover call as there is no unhover Jquery call. This works very well in fact!
Advertisements

From → Uncategorized

Leave a Comment

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: