2013-07-29 94 views
0

這是到目前爲止我的HTML代碼:查找DOM樹中的特定元素?

<div class="span4"> 
    <div class="feature_plus"> 
    </div> 
</div> 
<div class="feature_content"> 
    <p>test 1</p> 
</div> 

<div class="span4"> 
    <div class="feature_plus"> 
    </div> 
</div> 
<div class="feature_content"> 
    <p>test 2</p> 
</div> 

<div class="span4"> 
    <div class="feature_plus"> 
    </div> 
</div> 
<div class="feature_content"> 
    <p>test 3</p> 
</div> 

爲了顯示工具提示的內容(以及做其他事情與jQuery),我想知道我怎麼能找到的內容接下來每個.feature_plus.feature_content

編輯:所以我要更精確地說一下:我使用Qtip2這裏是不工作我的代碼:

$(document).ready(function() 
{ 
    $('.feature_plus').qtip({ 
     content: { 
      text: $(this).parent().next('.feature_content') 
     }, 
     style: { 
      classes: 'qtip-dark qtip-rounded qtip-shadow' 
     }, 
     position: { 
      my: 'top left', // Position my top left... 
      at: 'bottom right' // at the bottom right of... 
     } 
    }); 
}); 

誰能幫助?

回答

1

$(這)是指在我的第一篇,以產生本身qtip。

所以我不得不思考方式使用jQuery的每個(),這裏是解決方案:

$(document).ready(function() { 
    $('.feature_plus').each(function() { 
     $(this).qtip({ 
      content: { 
       text: $(this).parent().next('.feature_content') 
      }, 
      style: { 
       classes: 'qtip-dark qtip-rounded qtip-shadow' 
      }, 
      position: { 
       my: 'top left', // Position my top left... 
       at: 'bottom right' // at the bottom right of... 
      }, 
      show: { 
       event: 'click', 
       solo: true 
      }, 
      hide: { 
       event: false 
      }, 
      events: { 
       show: function (event, api) { 
        // Trying to hide the elem triggering qtip 
        $(this).hide(); 
       }, 
       hide: function (event, api) { 
        // Trying to show the elem triggering qtip on qtip hide 
        $(this).show(); 
       } 
      } 
     }); 
    }); 
}); 
+0

+1我想知道爲什麼它不是'無論是工作。顯然qtip不處理$(this),就像jQuery處理它一樣。因此,爲了在一個類中使用多個工具提示,您需要將其封裝在一個.each中,就像您在此處顯示的那樣。謝謝! –

2

您可以使用類似:

$('.feature_plus').parent().next('.feature_content').html(); 

如果是這樣的佈局會是什麼,每次等。

jsFiddle here.

+0

你好感謝你的努力,我已經編輯我的問題更精確。我試過你寫過的東西,但它不起作用,也許是因爲我使用$(this)我不知道:-) –

+0

@HugoTrial檢查$(this)的值是多少。我不知道qtip是如何運作的,所以你需要爲我提供一個jsFiddle使用它或其他東西 – lifetimes

0

試試這個:

$(".feature_plus").parent().next(".feature_content").html() 
+0

你好,謝謝你的努力,我編輯我的問題更加精確。我已經嘗試過你所寫的,但它不工作,也許這是因爲我使用$(這個)我不知道:-) –

0

試試這個:

$('.feature_plus').parent().next().html(); 
+1

請看看[answer] – JimHawkins