开发者

jQuery; Help with selectors

Hey guys some help needed with jQuery.

I have 5 icons linked to 5 pictures, so I am fading out icon and fading in larger version.

$('#iconX').click(function() {
    $('.iconSet').fadeOut('300');
    $('#largeX').delay('300').fadeIn('300');
});

<!-- Small images -->

<a href="#" ><img src="images/icon1.png" class="smallPics" id="icon1"/></a>
<a href="#"><img src="images/icon2.png" class="smallPics" id="icon2"/></a>


<!-- Large images -->

<img src="images/large1.png" class="largePics" id="large1" />
<img src="images/large2.png" class="largePics" id="large2" />

How can I use instead of X's (#iconX , #largeX) , something like icon1 and large1 and find out which exactly icon was chosen and how can I use it later in largeX ? Hopefully it makes any sense,开发者_如何学编程 and sorry for question title, did not really know how to name it :)


$('img[id^="icon"]').click(function() {
    $(this).fadeOut('300');
    var largeId = this.id.replace('icon', 'large');
    $('#'+ largeId).delay('300').fadeIn('300');
});
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜