jQuery: How to find an image by its src

Viewed 85429

I need to find an img by name and src. I have been trying the following to no avail.

var s = $("img[src='/images/greendot.gif'][name='BS']");

The html:

<img alt="This item is active." name="BS" src="/images/greendot.gif"/>

vs

<img alt="This item is not active." name="BS" src="/images/spacer.gif"/>
4 Answers

without seeing the html I would say check your path.

$("img[src$='greendot.gif'][name='BS']")

given the following HTML:

<img src="http://assets0.twitter.com/images/twitter_logo_header.png" name="logo" />

this jquery worked:

var x = $("img[src$='twitter_logo_header.png'][name='logo']");
alert(x.attr("src"));

Try losing the quotes:

var s = $("img[src=../../images/greendot.gif][name=BS]");
Related