Reputation: 13
I'm trying to refactor my existing code to now use jQuery and I can't figure out how to append my info to my src
Here was my existing line:
document.getElementById("itemDetail").src = detailUrl;
This is what I'm trying:
$("#itemDetail img src").append(detailUrl);
This is my snip of html:
<div id="detailsPane">
<img src="images/blank-detail.jpg" width="346" height="153" id="itemDetail" />
</div>
Upvotes: 1
Views: 7820
Reputation: 4370
this line:
document.getElementById("itemDetail").src = detailUrl;
in jQuery is:
$('#itemDetail').attr('src'...
you need
$('#itemDetail').attr('src',function(i,e){
return e+=detailUrl;
})
Upvotes: 0
Reputation: 358
use attr
example:
$(this).attr("src", src);
you can see more in http://api.jquery.com/attr/
Upvotes: 3
Reputation: 620
You're almost there.
detailUrl = 'image.png';
$("#itemDetail").attr('src', detailUrl);
Upvotes: 1
Reputation: 24001
First of all your selector should be $("img#itemDetail")
> If you need to set src you can use
$("img#itemDetail").attr('src' , detailUrl);
> If you need to append to the src you can use
$("img#itemDetail").attr('src' , $("img#itemDetail").attr('src') + detailUrl);
Upvotes: 2