2

I'm trying to make some hover actions using jQuery, but I think the selector isn't working. Here's the HTML:

<div id="footer">
            <ul>
                <li><a href="#">Start a Something</a></li>
                <li><a href="#">Send a Gift</a></li>
                <li><a href="#">How It Works</a></li>
                <li><a href="#">Secure Service</a></li>
                <li><a href="#">About Company</a></li>
                <li><a href="#">Blog</a></li>
                <li><a href="#">Contact</a></li>
            </ul>

            <ul>
                <li>&copy; 2012 Company</li>
                <li><a href="#">Terms of Use and Privacy</a></li>
            </ul>
        </div>

And here's the jQuery:

$('#footer ul li').mouseover(function(){
        $(this).animate({
            color: "white"
        }, 200);
    }).mouseout(function(){
        $(this).animate({
            color: "#bcbdbd"
        }, 200);
});

What selector should I be using?

Musa
  • 96,336
  • 17
  • 118
  • 137
Tom Maxwell
  • 9,273
  • 17
  • 55
  • 68
  • Looks valid to me, maybe you need to wrap everything on `document.ready` – Explosion Pills Jan 10 '13 at 01:56
  • -1 define "not working" and summarize it in the title; e.g. does `$(the_selector)` return a set of 0 elements or ..? –  Jan 10 '13 at 02:03
  • Wrap with document.ready and $('#footer ul li a') to make the selector work, but still you can't animate color. Proof that it works: http://jsfiddle.net/Mhp2c/10/ To animate color, check out http://motyar.blogspot.se/2010/07/animate-color-using-jquery.html – Robin Manoli Jan 10 '13 at 02:13
  • Your question has an answer [here](http://stackoverflow.com/questions/7516407/jquery-animate-text-color) – jec Jan 10 '13 at 02:13

4 Answers4

5

Why oh why are you using jQuery for this task?

RAW CSS!

#footer ul li a { /* or even just "#footer a" */
    color: #bcbdbd;
    transition: color 0.2s ease;
    -webkit-transition: color 0.2s ease;
    /* Chrome does not yet support the un-prefixed version */
}
#footer ul li a:hover { /* same comment as above */
    color: #fff;
}
Niet the Dark Absol
  • 320,036
  • 81
  • 464
  • 592
3
$('#footer ul li a').hover(...

They're links so color on the <li> won't change them.

Jason
  • 3,330
  • 1
  • 33
  • 38
2

I think you should be using:

$('#footer ul li a');

Your selector isn't wrong, but you should be applying those actionhandlers and animations to the <a> tags instead.

adjusting color in the wrapping <li> won't override the color that was default with the <a> tags

EDIT:

As to the answer of what you want to achieve, you will have problems trying override the CSS :hover with JQuery alone. But JQuery UI employs http://api.jquery.com/jQuery.cssHooks/ in their animate() http://jqueryui.com/animate/

Using that, using animate on .hover() or .mouseover() will override the default CSS :hover properties to use the JQuery's animate.

Example: http://jsbin.com/udahe3/399/

Answer elsewhere on SO: Override a:hover with jQuery?

Community
  • 1
  • 1
Calvin
  • 1,305
  • 8
  • 17
1

You could target the A element instead:

$('#footer ul a')
brain
  • 2,507
  • 1
  • 13
  • 12