Jquery - determining which link was clicked

后端 未结 5 1989
轮回少年
轮回少年 2020-12-20 07:18

I have several similar links that trigger different navigation divs to appear. I am trying to find a way in JQuery to determine which of the links was clicked and then trig

5条回答
  •  死守一世寂寞
    2020-12-20 07:40

    you can use rel

    html:

    Click me
    Click me
    Click me
    
    
    Foo
    Foo
    Foo

    javascript:

    $('.expander').click(function(e) {
       $('#' + $(this).attr('rel')).toggle();
       e.preventDefault();
       return false;
    });
    

    You can use .index() if you want to know the relative position of the ancho being clicked, you need to wrap the anchors though:

    jsfiddle

提交回复
热议问题