views:

84

answers:

1

Suppose that you have:

<a href="file://...">link1</a>
<a href="file://...">link2</a>
<a href="http://..."&gt;link3&lt;/a&gt;
<a href="http://..."&gt;link4&lt;/a&gt;

What code should I use to select only link1 and link2 without using a[href^=http]?

+3  A: 

That's exactly how you would do it:

$('a:not(a[href^=http])')

or

$('a[href^=file]')

What's wrong with selecting based on the href attribute?

Matt Ball
@MattBall, it's just a matter of testing and learning.Thanks so much
green_tea2009
You have to read the jQuery selector API very carefully; every character matters. For instance, `$('a:not(a [href^=http])')` won't work.
Matt Ball
a:not(a[href^=http]) is not working at all. I just tested.
green_tea2009
I just tested it as well, and it works for me. I copy-and-pasted the first method I suggested. Are you not using the latest version of jQuery?
Matt Ball
I was using jquery 1.2... now i changed to use 1.3 and it works now
green_tea2009