开发者

jQuery fadeout question

开发者 https://www.devze.com 2023-04-04 02:00 出处:网络
I\'m wondering how i can fadeout a class element in jQuery. I\'ve got a list of div\'s and all of them got the same class name. So, if i click on of them, all fades out. How can i make it so just the

I'm wondering how i can fadeout a class element in jQuery. I've got a list of div's and all of them got the same class name. So, if i click on of them, all fades out. How can i make it so just the one I'm clicking is fading out?

        $(document).ready(function() {
           $('.imageWrap').click(function() {
               $(this).fadeOut();
           }
        });

I've been checking the jq开发者_如何学JAVAuery docs but i can't find any solutions too this. I know it's a basic question but i hope someone can help me out. Thanks!


This will work as you expect it but you have a typo:

    $(document).ready(function() {
       $('.imageWrap').click(function() {
           $(this).fadeOut();
       }); // < - missing parathesis and semicolon
    });

jsFiddle: http://jsfiddle.net/NTtqx/


That code you have above should be fading just the image you click on out, he $(this) part selects just the image that has been clicked on and then fades it out, your issue is the typo, you've got a missing ):

$('.imageWrap').click(function() {
     $(this).fadeOut();
}) //ADD THE CLOSING BRACKET HERE

I've pretty much copied your code line for line in this JSFiddle and as you can see when you click on one div just that div fades out: http://jsfiddle.net/SMtuG/, so it's clearly just the typo causing this issue.


You forgot to close 'click' event with '});':

$(document).ready(function() {
   $('.imageWrap').click(function() {
       $(this).fadeOut();
   });
});
0

精彩评论

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

关注公众号