Scott Selby
Scott Selby

Reputation: 9580

change img src with jQuery

There are many answers on SO that show how to set an img src with .attr in jQuery. For some reason this is not working.

<img id="imgMap" style="position:absolute;bottom:7px;right:7px;width:250px;height:250px;" />

<script>
$(function () {   
    $("#imgMap").attr( 'src', 'http://maps.googleapis.com/maps/api/staticmap?center=41.886456,-87.62325&zoom=14&size=250x250&sensor=false&markers=color:blue%7Clabel:S%7C41.886456,-87.62325');
});
</script>

But the exact same url put inline in the HTML works fine

<img id="imgMap2" runat="server" src="http://maps.googleapis.com/maps/api/staticmap?center=41.886456,-87.62325&zoom=14&size=250x250&sensor=false&markers=color:blue%7Clabel:S%7C41.886456,-87.62325" style="position:absolute;bottom:7px;right:7px;width:250px;height:250px;" />

Upvotes: 1

Views: 240

Answers (2)

Harish Ambady
Harish Ambady

Reputation: 13151

your code works fine for me, here is the link: jquery set attribute value

Upvotes: 0

Adam Merrifield
Adam Merrifield

Reputation: 10407

This works fine: http://jsfiddle.net/ypDZw/

Upvotes: 1

Related Questions