tags:

views:

1400

answers:

2

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"/>
+1  A: 

Try losing the quotes:

var s = $("img[src=../../images/greendot.gif][name=BS]");
karim79
That didnt help.
kjgilla
Try with the path you've shown in the HTML, i.e. ../../images/greendot.gif. I've edited the answer.
karim79
There was a mixup there. I originally had ../../images/greendot.gif and it still wasnt working. I then switched to /images on the dynamically add images (js added) but the ones coming down from .net where still ../. At any rate something about the '/' in the attr search were screwing things up.
kjgilla
+6  A: 

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"));
Jared
There's no need for a $ when we have the full path. Also, thanks for the down-vote.
karim79
Awesomeness!!!!!
kjgilla
My path is ok but this will make me path agnostic (pathnostic).
kjgilla
+1 I got ya Jared
TStamper