74

Is it possible to create a CSS rule that would apply a style to any IMG tag with a SRC that contained a specific string, say "hideme"? For instance, if I had the following 3 images on a page it would hide the second one?

<img src="images/test1.png">
<img src="images/hideme.gif">
<img src="images/test3.jpg">
BoltClock
  • 700,868
  • 160
  • 1,392
  • 1,356
  • can you give more information on the situation you would use this? – David Nguyen Jul 20 '11 at 14:59
  • 4
    This just became a "popular question" and I wish I remembered why I even wanted to do this :) –  Nov 28 '12 at 19:19
  • I believe this was a situation where I could not modify the HTML, but only "side-load" some CSS. Based on the date, it may have been customization to CA Service Catalog. FWIW. ¯\\_(ツ)_/¯ –  Mar 11 '20 at 14:57

1 Answers1

159

Use this CSS3 attribute selector:

img[src*="hideme"] {
    display: none;
}

I'd prefer to use a hideme class instead, but if you must hide an image based on its src attribute, the above is fine.

BoltClock
  • 700,868
  • 160
  • 1,392
  • 1,356
  • 1
    As usual, some versions of IE are known to have bugs with CSS3 attribute selectors. The SitePoint Reference is useful: http://reference.sitepoint.com/css/css3attributeselectors – BoltClock Jul 20 '11 at 15:00