5

I am having issues with this: I want to force a hover function over the image when infact hovering over the h3 element

html:

<p><a><img class="size-full wp-image-1236 alignleft" alt="phone-icon-red" src="..." width="50" height="50" /></a></p>
<h3>Contact Us</h3>

CSS:

img:hover{
    margin-left: 10px;
}

js:

$('h3').hover(function(e){
                e.preventDefault();
                $(this).prev('p').find('img').trigger('mouseover');
            });

See my fiddle

2 Answers 2

4

I have workaround for your issue.

Add img class same as hover pseudo class:

img:hover, img.hover{
    margin-left: 10px;
}

Bind mouseover and mouseout events to h3 element:

$('h3').on({
    'mouseover': function() {
        $(this).prev('p').find('img').addClass('hover');
    },
    'mouseout': function() {
        $(this).prev('p').find('img').removeClass('hover');
    }
});

fiddle

Sign up to request clarification or add additional context in comments.

Comments

2

you can use multiple jQuery event handlers:

$("h3").on({
    mouseenter: function(){
        $('img').addClass('imgHoverClass');
    },
    mouseout: function(){
        $('img').removeClass('imgHoverClass');    
    }
});

working example: http://jsfiddle.net/7L4WZ/169/

enjoy :)

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.