jQuery check if target is link

后端 未结 7 1387
傲寒
傲寒 2021-02-07 23:49

I have a global function to capture clicks.

$(document).click(function(e){
  //do something
  if(clickedOnLink)
    //do something
});

I want t

相关标签:
7条回答
  • 2021-02-08 00:28

    Updated: You could check if the target is an a or if a parent is an a.

    $(function () {
        $(document).on('click', function (e) {
            $target = $(e.target);
            if ($target.closest('a').length > 0) {
                alert('i am an a');
            }
        });
    });
    

    http://jsfiddle.net/8jeGV/4/

    0 讨论(0)
提交回复
热议问题