We help IT Professionals succeed at work.

jQuery: how to select and fadeOut an image based on container ID and 'src' attribute

Brad Bansner
Brad Bansner asked
on
Given the attached HTML, lets say I have a variable such as:

var replaceImage='art/gr_number_1.jpg';

How can I select the image based on its container ID (the DIV) and its 'src' attribute? I tried these two things with no luck:

$('img[src$=removeImage]').fadeOut(200);
$('src', removeImage).fadeOut(200);

Thanks!
<div id="question1">
<img class="ranknum" src="art/gr_number_1.jpg" width="200" height="240" border="0" />
</div>

Open in new window

Comment
Watch Question

try

$('#question1 > img[src="'+replaceImage+'"]').fadeOut(200);
Brad BansnerWeb Developer

Author

Commented:
I tried that, didn't work. Then removed the > sign, now it works. Should that really be needed?