Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

on hover do a check on the background-color of the element

Posted on 2011-09-29
7
Medium Priority
?
243 Views
Last Modified: 2012-05-12
When the .hover( ) fires on element, I want to check what the background-color of that element is.

How can I do this in jQuery?
0
Comment
Question by:Tom Knowlton
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 2
7 Comments
 
LVL 15

Expert Comment

by:Eyal
ID: 36818502
0
 
LVL 5

Author Comment

by:Tom Knowlton
ID: 36818715
It does not seem to be working properly in my .hover(  )   code:


What happens is when I select a row in a table, the background of that row is highlighted in a color.

If I hover over that row and then leave it....I want the background color to stay as it was, I don't want it to change.  This is okay for rows that are not selected, but not for a selected row.


Here is my current jquery scripting:

var curbkcol = "";

    $('tr:gt(0)', 'table[id*="ShoppingShippingMethods1"]').hover(
                function ()
                {
                    curbkcol = $(this).css("background-color");

                    $(this).css({
                        "background-color": "#FEF8A9",
                        color: "black"
                    });
                },
                function ()
                {
                    $(this).css({
                        "background-color": "white",
                        color: "black"
                    });

                    if (curbkcol == "rgb(254,248,169)")
                    {
                        $(this).css({
                            "background-color": "#FEF8A9",
                            color: "black"
                        });

                    }
                }
                );

Open in new window

0
 
LVL 40

Assisted Solution

by:Gurvinder Pal Singh
Gurvinder Pal Singh earned 1000 total points
ID: 36848909
i guess first you have to define the default color in a class, and then toggle that class with another one in case of hover, like this
http://stackoverflow.com/questions/275891/jquery-hover-and-class-selector

$('tr:gt(0)', 'table[id*="ShoppingShippingMethods1"]').hover(
    function(){
        $(this).css ("background-color", "#FEF8A9");
    },
    function(){
        $(this).css ("background-color", "#fff");
    } );

0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
LVL 5

Author Comment

by:Tom Knowlton
ID: 36891868
This takes care of the hover effect, but what about when a row is already selected, and then I hover over the row?

Typically the row loses its selection color and returns to the normal color, because that is what the hover function do.  Except in the case of an already selected row, this behavior is not desired.

So how can I have an exception for the already selected row?
0
 
LVL 15

Accepted Solution

by:
Eyal earned 1000 total points
ID: 36893651
play with classes and not with css directly
this way you can add/remove hover class when hovering the row
when you will remove the class the old class will apply. if you had there selected class it will stay selected otherwise it will return to unselected
0
 
LVL 5

Author Comment

by:Tom Knowlton
ID: 36904503
>>>play with classes and not with css directly

====================

I think this is where I will be heading, once I get more time to try this out.
0
 
LVL 5

Author Closing Comment

by:Tom Knowlton
ID: 37008208
thx
0

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

PROBLEM: The other day I was working on adding an ajax request to a webpage that already had a dialog box on the page.  The dialog box was using relative positioning to be positioned next to a form field I had on the page.  Everything was working…
This article discusses how to create an extensible mechanism for linked drop downs.
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
Suggested Courses

609 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question