ToddT ToddT - 5 days ago 4
HTML Question

jQuery append with variable as src

Just learning jQuery and cannot get my variable into

src
when I use
append
. It either doesn't work at all, or I just get the string representation of my variable name when I look in the console.

This is my offending code:

var $googleURL = "http://maps.googleapis.com/maps/api/streetview?size=600x300&location="+$googleStreet+","+$googleCity;

$($body).append('<img src='$googleURL'></img>');


I don't want to use
attr
because there is no
img
tag on the page, just a
body
tag. Where did I go astray?

Answer

please try

  $($body).append("<img src='"+ $googleURL + "'></img>");