How to ignore click event when clicked on children

前端 未结 5 1218
北海茫月
北海茫月 2020-12-05 17:39

So I have the following scenario:

Sample text. Anchor link
5条回答
  •  感情败类
    2020-12-05 18:15

    You can test which node was clicked with the target property of the event object:

    $("#block").click(function(event) { 
        if(event.target.nodeName != 'A') {
            alert('test');
        }
    });
    

    I suggest to read Event Properties from quirksmode.org.

提交回复
热议问题