开发者

jquery preventDefault not working

Why is my below preventDefault not working? can't seem to figure it out on this one

$(function() {
  $('a.action-link').bind('click', function(e){
    if(!$(this).hasClass('active')) {
      e.preventDef开发者_JAVA百科ault();
      $('#guts').fadeTo(333, 0.2);
      $('ul#slider').fadeOut(333, 'easeOutExpo', function() {
        $(this).fadeIn(333, 'easeInExpo');
      });
      return false;
    });
  }
});


Your brackets/parentheses don't match up. I'm not sure how any of it could work.

$(function() {
    $('a.action-link').bind('click', function(e){
        if(!$(this).hasClass('active')) {
            e.preventDefault();
            $('#guts').fadeTo(333, 0.2);
            $('ul#slider').fadeOut(333, 'easeOutExpo', function() {
                $(this).fadeIn(333, 'easeInExpo');
            });
            return false;
        }
    });
});


Seems that was only a syntax mistake:

      return false;
    });
  }
});

to

      return false;
    }
  });
});

This works as in the fiddle:

http://jsfiddle.net/UnahA/1/

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜