I got the following code:
HTML
<div class="image">
<img src="http://ecx.images-amazon.com/images/I/41ghiuvjdvL._SL75_SS50_.jpg" />
</div>
<br />
<div class="photo">
<img src="http://profile.ak.fbcdn.net/hprofile-ak-ash2/27520_119569768054263_2432_q.jpg" />
</div>
JS
// getting src of bottom image
var bottomSrc = $(".photo img").find("src");
// getting src of top image
var topSrc = $(".image img").find("src");
$(".photo").click(function() {
// changing sources
// topSrc.attr("src", bottomSrc);
// topSrc.replaceWith(bottomSrc);
topSrc.replace(bottomSrc);
})
When the bottom image is clicked, I want the src of the top image to be replaced with the bottom image's src, so that both images are the same.
Why does the supplied code does not work?
.attr('src')to get the value of the src attribute, not.find()which finds child elements