2012-03-14 51 views
0

這是一個很常見的問題,但我無法弄清楚。讓我先發布我的代碼:jQuery - 無法選擇正確的div

<div class="myDeskContentRate"> 
    <span class='myDeskContentStar'><img src='star.png'></span> 
    <div class='myDeskContentRateCount'><span class='starCount'>1</span></div> 
</div> 

而且我的jQuery:

$('.myDeskContentStar').click(function(){ 
     $postId = $(this).attr('networkPostId'); 
     $this = $(this); 
     $starCount = $this.next('.myDeskContentRateCount'); 

     $.post('/includes/classes/handler.php?do=networkPostStar', { postId : $postId }, 
     function(data){ $this.html(data); $starCount.nextUntil('.starCount').load('/includes/classes/handler.php?do=networkPostStarCount', { postId : $postId }); }); 
}); 

當一個明星的點擊它不得不這樣做後,然後負載,因爲它有更新的恆星數量。

我的問題是什麼,我不能選擇跨度類=「歷史starcount」股利類的內部=「myDeskContentRateCount」

我可以得到class ='myDeskContentRateCount'但這不是我想要的。有沒有辦法讓我獲得span class ='starCount'

在此先感謝。

回答

2

希望這將解決你的問題:

$starCount = $this.next('.myDeskContentRateCount').find('.starCount'); 
+0

這樣做:-) – skolind 2012-03-14 10:55:03

+0

很高興幫助:) – 2012-03-14 10:55:22

1
$('div.myDeskContentRate > div.myDeskContentRateCount > span.starCount'); 

會選擇它。其他的可能性

$('div.myDeskContentRateCount').child('span.starCount'); 
$('div.myDeskContentRateCount').find('span.starCount'); 
+0

這完美地工作了太:)既然你是第一個,你會得到答案標記:) – skolind 2012-03-14 10:55:48

+0

歡迎您;-)這是非常好的:-) – 2012-03-14 10:56:07

+0

那麼,在4分鐘內,我會;) – skolind 2012-03-14 11:01:23