Reputation: 3258
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?
Upvotes: 0
Views: 3599
Reputation: 198
With Javascript, you can put variables inside strings using +
Like this: "string, " + variable + ", more string"
Try this code, it may work depending on what you're trying to accomplish.
var googleURL = 'http://maps.googleapis.com/maps/api/streetview?size=600x300&location='+googleStreet+','+googleCity;
$($body).append('<img src="' + googleURL + '"></img>');
Upvotes: 1
Reputation: 547
please try
$($body).append("<img src='"+ $googleURL + "'></img>");
Upvotes: 2