PDA

View Full Version : Jquery hover


wyclef
03-24-2009, 02:18 AM
Hey, how do I get a jquery hover coded more efficiently than this so that the text also triggers the image hover as well. The way this is set up seems really crummy. heres the link

dynodealz.com/crum/crum.html

don't worry about the missing image.

TinyScript
03-24-2009, 02:38 AM
looks like you need to put the text into an anchor
<a>text</a>

wyclef
03-24-2009, 02:42 AM
it doesnt validate if i put heading tags within a link tag

TinyScript
03-24-2009, 02:47 AM
I see
put anchors in the h tags
<h2><a>text</a></h2>

edit: that doesn't work

wyclef
03-24-2009, 02:49 AM
but i've got 2 sets of h tags. if i put anchors in both then i have to duplicate the same link.

TinyScript
03-24-2009, 02:58 AM
it doesnt validate if i put heading tags within a link tag
Quoted from somewhere on the internet:
that's not valid HTML -- even if many browsers will recover from the error. The anchor tag is an inline element, and it should not contain a block element such as a div, h1, p and so on.

wyclef
03-24-2009, 03:05 AM
ok, any other ideas?

Eldarrion
03-24-2009, 08:27 PM
Or you could always change the infoFade function to look like this:


function infoFade() {
$('.picture a').hover(
function () {
$(this).find('strong').fadeIn('normal');
},
function () {
$(this).find('strong').fadeOut('normal');
}
);
$('h6').hover(
function () {
$('.picture a').find('strong').fadeIn('normal');
},
function () {
$('.picture a').find('strong').fadeOut('normal')
}
)
$('h5').hover(
function () {
$('.picture a').find('strong').fadeIn('normal');
},
function () {
$('.picture a').find('strong').fadeOut('normal')
}
)
}


Also, you don't need to have that function inside $(document).ready and can safely pull it out, and just leave the call to it in there. Enjoy.

Eldarrion
03-24-2009, 08:38 PM
And yet another way to go about it is to just assign the hover function to the '.picture' class, instead of '.picture a', which would definitely remove the need to duplicate the code, though you will get hovers even when not over the text, but over the div itself. Or just use .each... like so:


function infoFade() {
$('.picture div').children().each(function() {
$(this).hover(
function () {
$('.picture a').find('strong').fadeIn('normal');
},
function () {
$('.picture a').find('strong').fadeOut('normal');
}
)
});
}


But eh, whichever floats your boat. Enjoy.

wyclef
03-25-2009, 08:35 PM
those look promising but i wasnt able to get either of those 2 to work...

Eldarrion
03-25-2009, 09:35 PM
those look promising but i wasnt able to get either of those 2 to work...

Very rarely do I post untested code. In this case, both options were tested with your mark-up. Upload a live version for me to diagnose and we'll see exactly where the problem is.

wyclef
03-25-2009, 09:59 PM
thx. not sure what happened but i restarted by computer and now the code works fine... haha... weird.