jQuery Drill down selector ?
Posted
by Etienne
on Stack Overflow
See other posts from Stack Overflow
or by Etienne
Published on 2010-05-04T17:52:07Z
Indexed on
2010/05/04
18:08 UTC
Read the original article
Hit count: 180
Hi, I have made this piece of code that makes a roll hover effect on any image you add the class 'simplehover' to it :
//rollover effect on links
$(".simplehover").mouseover(function () {
$(this).attr("src", $(this).attr("src").replace("-off.", "-on."));
}).mouseout(function () {
$(this).attr("src", $(this).attr("src").replace("-on.", "-off."));
});
<img src="slogan.gif" class="simplehover" />
Im trying to get it work if you add the class 'simplehover' to the surrounding element : . (especially usefull for ASP.net asp:HyperLink tag which automatically generate the IMG tag inside the hyperlink.
<a href="#" class="simplehover"> <img src="slogan.gif" /> </a>
If I change my selector for : $(".simplehover img") , it will work, however it no longer works in senario #1.
I tried this with no luck:
$(".simplehover").mouseover(function () {
if ($(this).has('img')) { $(this) = $(this).children(); }
...
Anyone can figure this out?
© Stack Overflow or respective owner