jQuery: adding class to link if its clicked

后端 未结 4 1743
有刺的猬
有刺的猬 2021-01-07 10:32

I call jquery function onclick at links. For example:

Content 1


        
4条回答
  •  孤城傲影
    2021-01-07 11:16

    Ok thanks for pasting the code, try this:

    First wrap the group of anchor tags in a div, so you can seperate them out from the other anchors on your page, and they will be grouped:

    So:

    
    

    Then try this JQuery code:

        $("#anchorGroup a").click(function() {
        $("#anchorGroup a").removeClass('active');
        $(this).addClass('active');
    
    });
    

提交回复
热议问题