jQuery CSS and Hover

Hello experts -
I attempting to produce a hover effect over a set of table cells where the 'selected' cell has a dark background, the 'non-selected' cells have no background and on hover the non-selected cells show as a lighter highlight.  I've done the following, which doesn't work right:
<%@ Page Language="VB" AutoEventWireup="false" CodeFile="test3.aspx.vb" Inherits="test3" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
    <style type="text/css">
        body { font-family:verdana; font-size:12px; }
        .td1 { padding-left:10px; padding-right:10px; }
        .selected { background:#00f; color:#fff; font-weight:bold; }
    </style>
    <script src="Scripts/jquery-1.7.1.min.js" type="text/javascript"></script>
    <script type="text/javascript">
        $(document).ready(function () {
            $('.td1').click(function () {
                $('.td1').removeClass('selected');
                $(this).addClass('selected');
            });
            $('.td1:not(.selected)').hover(function () {
                $(this).css({ 'cursor': 'pointer', 'background': '#b0e2ff' });
            },
            function () {
                $(this).css({ 'cursor': 'default', 'background': 'inherit' });
            });
        });
    </script>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <table cellspacing="0" cellpadding="0" border="1">
            <tr>
                <td class="td1 selected">Fee</td>
                <td class="td1">Fie</td>
                <td class="td1">Fo</td>
                <td class="td1">Fum</td>
            </tr>
        </table>
    </div>
    </form>
</body>
</html>

Open in new window

When one of the non-selected cells is clicked I want it to switch to the darker blue, with the hover behavior then moving to the new collection of non-selected cells.  There should be no hover effect above the selected cell.

Can someone give me an assist on how to accomplish this?  Thanks.

-- Rick
MinnRickAsked:
Who is Participating?
 
MinnRickAuthor Commented:
Solved.  Here's what ended up working for me:

<%@ Page Language="VB" AutoEventWireup="false" CodeFile="test3.aspx.vb" Inherits="test3" %>
<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
    <title></title>
    <style type="text/css">
        body { font-family:verdana; font-size:12px; }
        td { padding-left:10px; padding-right:10px; }
        .td1:hover { cursor:pointer; background:#b0e2ff; }
        .selected { background:#00f; color:#fff; font-weight:bold; }
    </style>
    <script src="Scripts/jquery-1.7.1.min.js" type="text/javascript"></script>
    <script type="text/javascript">
        $(document).ready(function () {
            $('td').click(function () {
                $('td').removeAttr('class').addClass('td1');
                $(this).toggleClass('td1 selected');
            });
        });
    </script>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <table cellspacing="0" cellpadding="0" border="1">
            <tr>
                <td class="selected">Fee</td>
                <td class="td1">Fie</td>
                <td class="td1">Fo</td>
                <td class="td1">Fum</td>
            </tr>
        </table>
    </div>
    </form>
</body>
</html>

Open in new window

0
 
StingRaYCommented:
In your stylesheet, insert "!important" to override the background color.

<style type="text/css">
        body { font-family:verdana; font-size:12px; }
        .td1 { padding-left:10px; padding-right:10px; }
        .selected { background:#00f !important; color:#fff; font-weight:bold; }
    </style>

Open in new window

0
 
MinnRickAuthor Commented:
Thanks StingRaY.  That's closer, but it's still not quite there.  The 'Fee' (first) cell isn't responding correctly on hover (background color or cursor) when one of the other cells is the selected one.  'Fee' does respond when clicked, but I want it to also get the pointer and light blue background when one of the other cells is selected.  Any thoughts on that?  Thanks again..
0
 
MinnRickAuthor Commented:
Points your way, StingRaY.  Thanks again for the input - you put me onto some new knowledge and that ultimately led to what I used.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.