jquery click event on anchor

前端 未结 4 1690
走了就别回头了
走了就别回头了 2021-02-05 14:43

Here\'s the snippet of html i have:


      
      
4条回答
  •  清酒与你
    2021-02-05 15:31

    The reason why your first code doesn't work because there are multiple anchors in your div content tag, hence when you associate anchor that resides in that tag with a click, it will generate ambiguity to in choosing exact anchor. You can target particular anchor by using its id attribute, and than associate the id with your events to target particular anchor. So the code will be as follows.

    T1 T2 T3

    And following will associate clicks to particular anchor.

    $("#tag-cloud-widget .content #anca").click(function(e) {
        alert('Anchor A clicked');  
        return false;  
    });
    
    $("#tag-cloud-widget .content #ancb").click(function(e) {
        alert('Anchor B clicked');  
        return false;  
    });
    
    $("#tag-cloud-widget .content #ancc").click(function(e) {
        alert('Anchor C clicked');  
        return false;  
    });
    

提交回复
热议问题