开发者

stopping an onclick event if its the tab already selected

How can i stop the following code executing if its ID is the one already selected?

Any help would be appreciated.

//Product Tabs
    $('#productinfowrap .tab:first').show();    
    $('#subselect li').click(function() {
        var thisTop = $(this).position().top;
        $('#subselect li').removeClass('current');
        var li = (this);
        $('.pointer').animate( {'top': thisTop}, function() { 
            $(li).addClass('current');
        });
        var id = $(this).find("a").attr('href');
        $("#productinfowrap > div").fadeOut(500).hide();        
        $(id).fadeIn();
        return false;
   开发者_StackOverflow中文版 });

and HTML

<ul id="subselect">
            <li class="current"><a href="#overview">Overview</a><span class="pointer"></span></li>
            <li><a href="#applications">Applications</a></li>
            <li><a href="#technical">Technical</a></li>
        </ul>


Check for the presence of the "current" class. IF it has it (meaning it is selected) don't do anything.

$('#subselect li').click(function() {
    if (!$(this).hasClass('current')){
            var thisTop = $(this).position().top;
            $('#subselect li').removeClass('current');
            var li = (this);
            $('.pointer').animate( {'top': thisTop}, function() { 
                $(li).addClass('current');
            });
            var id = $(this).find("a").attr('href');
            $("#productinfowrap > div").fadeOut(500).hide();        
            $(id).fadeIn();
    }
            return false;

        });
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜