tags:

views:

99

answers:

2

Hi can someone please explain what I am doing incorrectly. I am trying to have an image (bub1) fade in when you mouseover a link (butt1) and fade back out when you mouse away. Thanks for any help.

I updated this based on the help here and added my html...

    <a href="#" class="butt1"><img src="images/button-1.png" alt="" class="home-butt-1"/></a>

<div class="bub1"><img src="images/bubble-bl.png" alt="" /></div>

    <script type="text/javascript">

$(function() {
    $('.bub1').hide();
    $('a.butt1').hover(function() {
        $(this).find('.bub1').fadeIn('fast');
    }, function () {
        $(this).find('.bub1').fadeOut('fast');
    });
});

</script>
A: 

Your syntax is wrong, it should be:

$(function() {
    $('a.bub1').hide();
    $('a.butt1').hover(function() {
        $('.bub1', this).fadeIn('fast');
    }, function () {
        $('.bub1', this).fadeOut('fast');
    });
});

Your error is "$(this).('.bub1')", when you want to select an element inside of another one, the syntax in $('.selector', '.parent_selector') or $('.selector', parentjQueryobj).

philhq
Hmm thanks for the response.. that doesnt work either though.. also, I messed up by putting a.bub1 (a not supposed to be there), it is not a link class but rather just an div holding an image
zac
What I would do is set an ID to your image and try $('#idOfYourImg').fadeIn('fast'); just to see if it works. If it doesn't work, the problem is with your hover event.
philhq
If you could provide the HTML you have it would help a lot.
philhq
I agree with @wedix, it's to know how to select out your images without seeing any markup.
karim79
+1  A: 

How about:

$(function() {
    var bub1 = $('.bub1').hide();
    $('a.butt1').hover(function() {
        bub1.fadeIn('fast');
    }, function () {
        bub1.fadeOut('fast');
    });
});
Nick Riggs