How to get ID of clicked element with jQuery

后端 未结 5 1983
花落未央
花落未央 2020-12-08 18:38

I have the following html:

link
link         


        
5条回答
  •  暗喜
    暗喜 (楼主)
    2020-12-08 19:19

    Your IDs are #1, and cycle just wants a number passed to it. You need to remove the # before calling cycle.

    $('a.pagerlink').click(function() { 
        var id = $(this).attr('id');
        $container.cycle(id.replace('#', '')); 
        return false; 
    });
    

    Also, IDs shouldn't contain the # character, it's invalid (numeric IDs are also invalid). I suggest changing the ID to something like pager_1.

    link
    
    $('a.pagerlink').click(function() { 
        var id = $(this).attr('id');
        $container.cycle(id.replace('pager_', '')); 
        return false; 
    });
    

提交回复
热议问题