2010-09-14 38 views
0

的所有文字,如果我有以下獲得來自特定元素(一個或多個)

var url = this.data; 
$.get(url, {}, function(data){ 
    alert(data); 


}); 

我能夠成功地遍歷並提醒如下:

<a href="javascript:void(0)" id="arboretum-smith" class="bullet" rel="251-195">&nbsp;</a> 
    <div class="popup" id="arboretum-smith-box"> 
     <h3>Title 1</h3> 
     <div class="popupcontent"> 
      <p>Description text to go here.</p> 
     </div> 
     <a class="close" href="javascript:void(0)">Close</a> 
    </div> 

<a href="javascript:void(0)" id="old-well" class="bullet" rel="251-245">&nbsp;</a> 
    <div class="popup" id="old-well-box"> 
     <h3>Title 2</h3> 
     <div class="popupcontent"> 
      <p>Description text to go here.</p> 
     </div> 
     <a class="close" href="javascript:void(0)">Close</a> 
    </div> 

<a href="javascript:void(0)" id="bell-tower" class="bullet" rel="100-100">&nbsp;</a> 
    <div class="popup" id="bell-tower-box"> 
     <h3>Title 3</h3> 
     <div class="popupcontent"> 
      <p>Description text to go here.</p> 
     </div> 
     <a class="close" href="javascript:void(0)">Close</a> 
    </div> 

但是我想做的事得到<h3></h3>'s之間的文字。標題1,標題2等什麼是最好的方式去做這件事?

回答

0

如果你希望字符串"Title 1Title 2Title 3"

$(data).find('h3').text() 

如果要在陣列(類似的對象)["Title 1", "Title 2", "Title 3"]

$(data).find('h3').map(function(){return $(this).text();}) 
1
alert($(data).filter('#arboretum-smith-box h3').text());