0
<a href="#">Get Here</a>

I need to hide above link by using css (display:none).How can I select that (i.e. link with 'Get Here' text)

Sampath
  • 63,341
  • 64
  • 307
  • 441

6 Answers6

2

It isn't possible to target an element based on its content. but, it is possible to target an href based on its link:

<a href="go/there.html">Get Here</a>

a[href="go/there.html"]{}

If you can have a value other than # in your href, this approach could work.

paceaux
  • 1,762
  • 1
  • 16
  • 24
1

No, not possible for css. Css is made for styling elements, not selecting texts. You can do it with jquery though:

$("a:contains('Get Here')").hide();
aksu
  • 5,221
  • 5
  • 24
  • 39
1

Not with CSS, but using jQuery:

$("a:contains('Get Here')").hide();

or

$("a:contains('Get Here')").css('display','none');
prograhammer
  • 20,132
  • 13
  • 91
  • 118
1

You can't do that with CSS. But even if you could, you shouldn't have done it, really. Never. Even forget about using javascript for this (if it was up to me I would exclude :contains filter from jQuery). This is very-very bad approach to style things. Because tomorrow you change the link text and your code breaks. What you really need to do is to use classes:

<a href="#" class="get-here">Get Here</a>

with the next CSS:

.get-here {
    display: none;
}
dfsq
  • 191,768
  • 25
  • 236
  • 258
0

If you need to do it automatically whenever that text appears (and you don't have control over the text), use jQuery as asku suggests.

If you have control over the text, it's much simpler to add a class to that link and style it. You can add the same class to all the links that need hiding.

HTML:

<a href="#" class="hide">Get Here</a>

CSS:

.hide {display: none}
Sinister Beard
  • 3,570
  • 12
  • 59
  • 95
0

With CSS3 you could also use a[rel="#"] {display:none}

Zach Saucier
  • 24,871
  • 12
  • 85
  • 147
jksloan
  • 184
  • 1
  • 4