2011-10-25 41 views
0

我有一個簡單的HTML,其中包含了一些HTML和刪除鏈接一個div:jQuery忽略父項?

<div class="item"> 
I am a text this section can contain a lot of html and stuff... 
<a class="del_button" href="#">Delete</a> 
</div> 

這裏是jQuery的部分:

$(".item").click(function(){ 
alert("Item clicked"); 
}); 

$(".del_button").click(function(){ 
alert("DELETE clicked"); 
}); 

如果我點擊「刪除」鏈接,二顯示消息框,「點擊項目」和「刪除點擊」 - 如果我點擊刪除按鈕,如何禁用「項目點擊」警報?

+1

可能重複http://stackoverflow.com/questions/2364629/jquery-stop-child檢查 - 觸發 - 父母事件) – Matt

回答

0
$(".del_button").click(function(e){ 

alert("DELETE clicked"); 
    e.stopPropagation(); 

}); 

你可以從這裏http://jsfiddle.net/tqT2u/

[jQuery的停止孩子觸發父事件(的