如果href为空,如何隐藏链接文本?

时间:2013-06-28 19:30:28

标签: jquery css href

我生成了一系列链接,有些链接有空白href。 我想。隐藏空白或者即使它似乎有#使用Jquery和/或CSS

链接看起来像

<a class="Highlighted" id="hyperlinkViewProfile" href="">text to hide</a>

3 个答案:

答案 0 :(得分:5)

使用CSS:

A[href=""], A[href="#"] {
  display: none;
}

这适用于没有href或href =“#”的链接。如果您想在href中将链接与任何位置匹配,请使用A[href~="#"]

在旧浏览器中没有测试,在这种情况下你可以使用jquery选择器。

答案 1 :(得分:1)

DEMO

$('a').filter(function(){return $(this).attr('href') === "" || $(this).attr('href') === "#"}).hide();

答案 2 :(得分:0)

一个简单的jQuery:

$("a[href=''], a:not([href])").hide(); 

可以修改选择器以包含#链接:

$("a[href=''], a:not([href]), a:[href='#']").hide(); 
相关问题