2011-05-13 45 views
1

試圖刪除的內容是如果標題(類名=「productnamecolor colors_productname」)包含文本「真」類「帶bnum」。jQuery的remove()方法爲每個類是否包含文本

基本上在下面的例子中,你不應該能夠看到在「真跟單員冰箱」任何「伯克特雄鹿」的價值,但它仍然應該對所有的人:

<table width="300px"> 
    <tr> 
     <td width="100%" valign="top"><a class="productnamecolor colors_productname" href=""> Star Griddle</a></td> 
    </tr> 
    <tr> 
     <td width="100%" valign="top"><table cellspacing="0" cellpadding="0" width="100%"> 
      <tbody> 
      <tr> 
       <td width="64%" valign="top"><font class="text colors_text rewardpoints"><span id="offers">Special Offers:</span><br> 
       <div class="bbucks"><img src="http://bit.ly/ihYMFL" id="bucks"> Earn <span class="bnum">2343</span> Burkett Bucks</div> 
       </font></td> 
       <td align="right" width="36%"></td> 
      </tr> 
      </tbody> 
     </table></td> 
    </tr> 
    <tr> 
     <td width="100%" valign="top"><a class="productnamecolor colors_productname" href=""> True Merchandiser Refrigerator</a></td> 
    </tr> 
    <tr> 
     <td width="100%" valign="top"><table cellspacing="0" cellpadding="0" width="100%"> 
      <tbody> 
      <tr> 
       <td width="64%" valign="top"><font class="text colors_text rewardpoints"><span id="offers">Special Offers:</span><br> 
       <div class="bbucks"><img src="http://bit.ly/ihYMFL" id="bucks"> Earn <span class="bnum">2343</span> Burkett Bucks</div> 
       </font></td> 
       <td align="right" width="36%"></td> 
      </tr> 
      </tbody> 
     </table></td> 
    </tr> 
    <tr> 
     <td width="100%" valign="top"><a class="productnamecolor colors_productname" href="">Generic Something</a></td> 
    </tr> 
    <tr> 
     <td width="100%" valign="top"><table cellspacing="0" cellpadding="0" width="100%"> 
      <tbody> 
      <tr> 
       <td width="64%" valign="top"><font class="text colors_text rewardpoints"><span id="offers">Special Offers:</span><br> 
       <div class="bbucks"><img src="http://bit.ly/ihYMFL" id="bucks"> Earn <span class="bnum">2343</span> Burkett Bucks</div> 
       </font></td> 
       <td align="right" width="36%"></td> 
      </tr> 
      </tbody> 
     </table></td> 
    </tr> 
    </table> 

問題我」具有m個是,它是做什麼的所有值,我只想要擁有它的字「真」每個標題下刪除值。所以即時通訊假設我的每一個錯誤。

$(document).ready(function() {  
    $(".colors_productname:contains('True')").each(function() { 
     $('.bnum').remove(); }); 

}); 

回答

1

,而不是一個全球性的選擇

$('.bnum') 

你需要使用當前上下文在你的函數的每一個方法的,考慮到該基地是不是在同一個TR,我們需要做一些DOM遍歷目標。

$(".colors_productname:contains('True')").each(function() { 
    $(this).closest('tr').next('tr').find('.bnum').remove(); }); 
+0

這沒有任何工作,我覺得這些都是真的有效不幸的是,「標題」和階級「帶bnum」是在單獨的「TR's..perhaps這是我們正在運行到問題 – ToddN 2011-05-13 14:23:44

+0

啊,錯過了,在html在我的顯示器上變得相當混亂。更新後才能在移除之前執行正確的Dom遍歷。 – Rob 2011-05-13 14:31:22

+0

這奏效了謝謝。 – ToddN 2011-05-13 14:33:35

0

應該不會是$(this).find('.bnum').remove()甚至更​​短:
$(".colors_productname:contains('True') .bnum").remove()

+0

這並沒有給定 – ToddN 2011-05-13 14:21:49

0

試試這個來代替:

$(document).ready(function() { 
    $(".colors_productname:contains('True')").each(function() { 
     $(this).find('.bnum').remove(); }); 
}); 
+0

的例子工作有沒有必要'。每()'都沒有。 – 2011-05-13 14:18:48

相關問題