2012-11-09 106 views
1

I have the following situation within a report that has the following <td> element. Please note that this can appear multiples times as it is a report.如何删除<a href> Link Tag for a Specific Value using Jquery

My question is, when the value is ‘N’, using jQuery, I would like to remove the whole <a href> tag and just display the value of ‘N’ alone, without the underline below it, otherwise if the value is ‘Y’ then leave it as it is.

For example:

<td align="center" headers="MPA_CHANGED"><a href="http://www.mysite.com" class="my-mpa">Y</a></td> 

<td align="center" headers="MPA_CHANGED">N</td> 
+0

在哪里值N来自哪里? – AnandVeeramani

+0

从数据库查询。只需要检查是否'N',那么就不需要href标签。谢谢。 – tonyf

回答

0

在你的td元素添加一个类名你选择,让你可以有更多的控制了目前所有的TD元素:用于如:“report_td”

所以HTML这个样子的:

<td align="center" class="report_td" headers="MPA_CHANGED">...</td> 

然后尝试这样的:

$(function(){ 
    $("td.report_td").each(function(i, e){ 
    var tdElement = $(e); 
    var value = tdElement.find("a").text(); 
    if(value == "N") { 
     tdElement.html("N"); 
    } 
    }); 
}); 
0
$('a').each(function() { 
if ($(this).text() == 'N') { 
    $(this).replaceWith('N'); 
} 
}); 
+0

为什么要用不同的方法添加完全相同的解决方案? – gdoron

+0

@gdoron你为什么在意?在我看来,它的美妙之处在于,有不同的方法来完成任务。也许OP或其他人查看这个不熟悉.each()处理程序,并可能从我的答案中学习....放松那里牛仔。 – VIDesignz

+0

我关心的是一个普通用户,当我寻求解决我遇到的问题的解决方案时,我不喜欢看到很多重复的答案。当然你不必同意,只是说出我的想法。好日子sherif。 – gdoron

相关问题