开发者

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"]')
开发者_如何学JAVA

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/


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.


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"])')
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜