Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I hide link text if the href is blank?

Tags:

jquery

css

href

I have a series of links being generated and some have a blank href. I want to .hide the blanks or maybe even if it appears to have a # using Jquery and/or CSS

The links look like

<a class="Highlighted" id="hyperlinkViewProfile" href="">text to hide</a>
like image 905
user2532981 Avatar asked Oct 16 '25 04:10

user2532981


2 Answers

With CSS:

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

This works for links with no href or with href="#". If you want to match links with a # anywhere in the href, use A[href~="#"]

Didn't test in old browsers, you may resort to jquery selectors in that case.

like image 172
LexLythius Avatar answered Oct 17 '25 18:10

LexLythius


DEMO

$('a').filter(function(){return $(this).attr('href') === "" || $(this).attr('href') === "#"}).hide();
like image 33
A. Wolff Avatar answered Oct 17 '25 17:10

A. Wolff



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!