I'm trying to get an <h2>
and it's sibling <p>
's background color to fade to a different color on hover and fade back to the original color when you're no longer hovering over it.
I can't seem to get it right..
Here's the JS I have:
jQuery('div.flex-caption h2').hover(function() {
jQuery( this ).css({background:'#2F2F2F'}).fadeIn( 500 );
jQuery( this ).sibling('p').css({background:'#2F2F2F'}).fadeIn( 500 );
},
function() {
jQuery( this ).css({background:'rgba(0, 0, 0, 0.5)'}).fadeIn( 500 );
jQuery( this ).sibling('p').css({background:'rgba(0, 0, 0, 0.5)'}).fadeIn( 500 );
});
jQuery('div.flex-caption p').hover(function() {
jQuery( this ).css({background:'#2F2F2F'}).fadeIn( 500 );
jQuery( this ).sibling('h2').css({background:'#2F2F2F'}).fadeIn( 500 );
},
function() {
jQuery( this ).css({background:'rgba(0, 0, 0, 0.5)'}).fadeIn( 500 );
jQuery( this ).sibling('h2').css({background:'rgba(0, 0, 0, 0.5)'}).fadeIn( 500 );
});
The HTML markup:
<div class="flex-caption">
<h2 class="captionTitle">TITLE</h2>
<div class="captionText">CONTENT</div>
</div>
` element in your markup
– Dan-Nolan Nov 11 '13 at 18:04