Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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/

like image 229
Okeydoke Avatar asked Mar 24 '11 01:03

Okeydoke


People also ask

How to change src of image in jQuery?

Answer: Use the jQuery attr() Method You can use the attr() method to change the image source (i.e. the src attribute of the <img> tag) in jQuery. The following example will change the image src when you clicks on the image.


1 Answers

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.

like image 95
Nobody Avatar answered Nov 15 '22 04:11

Nobody