I'd really appreciate someones help as this is driving me nuts!
So I've got the following two imgs that sit next to each other, and are used in various places throughout the page.
<img class="curtain containerLeft" src="http://example.com/containerleft.jpg" />
<img class="curtain containerRight" src="http://example.com/containerright.jpg" />
What I need is when I hover over either of the two images, for a class of .lefthover or .righthover to be added to the left or right container at the same time and then to be removed again when mouseout. So the code on hover would look as so:
<img class="curtain containerLeft lefthover" src="http://example.com/containerleft.jpg" />
<img class="curtain containerRight righthover" src="http://example.com/containerright.jpg" />
and revert to this on mouseout:
<img class="curtain containerLeft" src="http://example.com/containerleft.jpg" />
<img class="curtain containerRight" src="http://example.com/containerright.jpg" />
I don't want the lefthover and righthover applied to every instance of these images on the page - just the two that I've moused over.
I've got close and tried many things but can only either get all instances of the images to have the appropriate classes added or only the image I've hovered over (not the one next to it.
And I can't figure out how to select another class in the same div (I can do it with .children, but this isn't appropriate in this instance). So I thought this might work for instance:
$('.curtain')
.hover(function() {
$(".containerLeft", this).addClass('lefthover');
$(".containerRight", this).addClass('righthover');
}, function() {
$(".curtainLeft", this).removeClass('lefthover');
$(".containerRight", this).removeClass('righthover');
});
Any ideas or thoughts?