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.

Sign up to request clarification or add additional context in comments.

1 Comment

Note that this will not work in all browsers (IE6 for instance).
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 Comment

That won't quite work, because it'd match a tags whose href attribute is exactly http://foo/, which isn't what he wanted.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.