1

I've got this test page going on: http://joshuacody.net/qworky/

Warning: Tons of CSS3. This will only look right in Safari or Chrome. Firefox will be tolerable. All else will be lost.

Essentially, when I hover on someone's name, I'd like it to trigger the hover state on their image as well. It's working now, but I feel the solution is inelegant. I'd rather not add more classes. Here it is:

$('a.name_link').hover(function(){
    $(this).parent('p').siblings('img').toggleClass('link_hover');
});

$('img.name_img').hover(function(){
    $(this).siblings('p').children('a').toggleClass('hover');
});

I thought the following would work:

$('a.name_link').hover(function(){
    $(this).parent('p').siblings('img').trigger('hover');
});

Any idea why it's not? I'm really looking for the cleanest, simplest way to do this. Thanks so much!

Joshua Cody
  • 3,742
  • 5
  • 32
  • 34

3 Answers3

0

from what i understand of the jquery hover method is that it accepts two functions

    $('a.name_link').hover(
               //mouse over
               function(){
                 $(this).parent('p').sibling('img').toggleClass('link_hover');
                },
               // mouse out
               function(){

               }
        );

since you're only declaring the first method, then maybe you should try triggering the mouseover method

$('a.name_link').hover(function(){
     $(this).parent('p').siblings('img').trigger('mouseover');
});

iangraham
  • 438
  • 3
  • 10
  • Hey iangraham, I should have mentioned, I've tried 'mouseover' and 'mouseenter', still with no luck. Also, I've been able to retrieve the 'src' and 'href' of the elements in questions via console.log – Joshua Cody Jan 20 '10 at 06:47
0

Instead of just one function, the hover function is supposed to have 2 functions. Try putting both functions on there.

jeffkee
  • 5,106
  • 12
  • 44
  • 76
0

Turns out I could just rework my CSS to do that, putting the img inside of the anchor tag.

Joshua Cody
  • 3,742
  • 5
  • 32
  • 34