2012-12-20 61 views
1

在此先感謝您的幫助。我正在使用下面的代碼來創建整個li「可點擊」。 問題是,如果您點擊除鏈接本身之外的任何實際文本(紅色,藍色&綠色統計),則返回「未定義」。看到這裏活鏈接:http://174.122.31.60/.如果直接點擊文本,可點擊的Jquery Div返回「undefined」

$(".available-properties li").click(function(){ 
window.location=$(this).find("a").attr("href"); 
return false; 

});

回答

0

只要改變這一點:

$(".available-properties li").click 

這樣:

$(".available-properties > li").click 

這樣,你只能選擇孩子的可供性UL元素的李。

1

試試這個代碼:

$(".available-properties li").click(function(){ 
window.location=$(this).parent().parent().find("a").attr("href"); 
return false; 
}); 

EXAMPLE

+1

爲什麼downvote?請解釋 –

0

這將工作。使用>點擊功能只能在父母身上工作,而不能在子女身上使用李。

$(".available-properties > li").click(function(){ 
    window.location=$(this).find("a").attr("href"); 
    return false; 
});​ 
0

你會得到一個競爭條件,如果你不篩選出的 'a':

$('.available-properties li').click(
     function(e) { 
      if(!($(e.target).is('a'))) { 
       window.location = $(this).children("a:first").attr("href"); 
      } 
     } 
    );