Okeydoke
Okeydoke

Reputation: 1357

jQuery image src selector

I’m trying to get a jQuery selector to return all the images that don’t have a certain src.

$('img[src!="/img/none.png"]')

These images are already transparent so, for performance sake I'm trying to exclude them from the ones that I fade in/out. But the query still returns the images with src = /img/none.png

If however I do

$('img[src="/img/none.png"]')

It will return only the images with src = /img/none.png. So it seems like the attribute not equal selector is broken?

Relevant documentation http://api.jquery.com/attribute-not-equal-selector/

Upvotes: 5

Views: 8555

Answers (2)

calvinf
calvinf

Reputation: 3914

Try using the :not selector.

$('img:not([src="/img/none.png"])')

If you're using a mixture of relative or absolute paths for the image you might want to use the "attribute ends with" selector as mentioned in another answer.

$('img:not([src$="/img/none.png"])')

Upvotes: 0

user578895
user578895

Reputation:

try

$('img:not([src="/img/none.png"])');

If that doesn't work, try

$('img:not([src$="/img/none.png"])');

depending on what browser you're in, the src isn't interpreted as what you set, it's interpreted as the absolute URI, so your browser thinks it's http://www.yoursite.com/img/none.png. I'm not sure how jQuery is reading the src so it may be picking up the absolute URI.

Upvotes: 10

Related Questions