1

I have a link that gets embedded dynamically by a script I run on a site. Let's say for arguments sake that the link looks like:

<a href="http://foo/bar.php" target="_blank">some stuff</a>

Is it possible to set a CSS Selector that will set display:none on all links containing http://foo/? Am I going to have to write a JavaScript event handler that checks for the injection into the DOM and then hide it through that?

What's the best way to handle this? If it's with JavaScript, can I see an example in jQuery?

2 Answers 2

2

Yes; there's a "starts-with" selector, as defined here. You would use: a[href^="http://foo/"]. Note that this isn't necessarily supported in all browsers.

1
  • Note that this will not work in all browsers (IE6 for instance). Commented Dec 30, 2009 at 17:46
0

I believe you can use a css selector to do this, but browser support may be limited.

a[href=http://foo/]

You can use the same selector with jQuery and it should work everywhere jQuery does.

$("a[href=http://foo/]")

More info on jQuery selectors can by found here: http://docs.jquery.com/Selectors

1
  • That won't quite work, because it'd match a tags whose href attribute is exactly http://foo/, which isn't what he wanted. Commented Dec 30, 2009 at 17:48

Not the answer you're looking for? Browse other questions tagged or ask your own question.