1

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;" /> 
3
  • setting 'src' of a div element wont do anything. you should rather use iframe. Commented Jul 23, 2012 at 16:20
  • 2
    Your code works fine here jsfiddle.net/r3vvr/2 Commented Jul 23, 2012 at 16:24
  • 1
    Works for me : jsfiddle.net/kWP6k Commented Jul 23, 2012 at 16:24

2 Answers 2

1

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

Sign up to request clarification or add additional context in comments.

1 Comment

there was one letter typo in the url - I'll accept this , because these other answers are very bad
0

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

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.