2015-06-04 85 views
0
頁面

我要刪除的文本「DocumentType:」從下面的HTML(我不關心標題或ALT):jQuery來刪除文本

<tr class="ms-gb" ishdr="true" isexp="true"> 
    <td colspan="100" nowrap="nowrap"> 
    <a href="javascript:" onclick="ToggleSPGridViewGroup(this, false)" title="Expand/Collapse DocumentType : Agreement - Contract"> 
     <img src="/_layouts/images/minus.gif" border="0" alt="Expand/Collapse DocumentType : Agreement - Contract"/> 
    </a> 
    &#160;DocumentType : Agreement - Contract 
    </td> 
</tr> 

在頁面中,我已經有一些JQuery的,通過了「MS-GB」入級元素循環,但我似乎無法潛入相應的元素中找到「Doc​​umentType:」按順序)與空文本進行.replace(:

<script type="text/javascript"> 
    $(document).ready(function() { 
     $(".ms-gb").each(function() { 
      var rowNums = $(this).nextUntil(".ms-gb").length; 
      $(this).children(0).append(" (" + rowNums + ")"); 
      $(this).html().replace("DocumentType : ",""); //This is horribly incorrect 
     }); 
    }); 
</script> 

如何正確鍵入此文本以取代「 DocumentType:「帶空字符串的文本?

回答

2

你必須設置html還有:

var currentHtml = $(this).html(); 
currentHtml = currentHtml.replace("DocumentType : ",""); 
$(this).html(currentHtml); 
+0

嗯它似乎並沒有爲我工作。我相信這是因爲我試圖替換沒有自己的span或div元素的文本(或者說,它是tr元素的子元素,其子元素具有多個html和text元素)。儘管我可以在這裏休息。有沒有一種方法可以替代TEXT而不是HTML? – Kolten