A href no innerHTML

Asked

Viewed 23 times

0

I’m using the Google API to insert a map into my site, where the user types in their zip code, street, etc, and the API shows the nearest accredited stores to that user, but I wanted to reference a store link when it’s shown on the map, currently the code that shows the stores is this:

  outputDiv.innerHTML += "<div class='espaco' style='margin-left:40px; margin-top:10px'> <a href='javascript:google.maps.event.trigger(closest[" + results[i].idx_closestMark + "],\"click\");'>" +   results[i].title  + '</a><br>' + results[i].address + "<br>" + results[i].distance.text + ' aproximadamente ' + results[i].duration.text + '<br><hr></div>';

Solved:

 + " <a href = 'goo.gl/maps/sQ5zPMJEERaggz3g8' target= '_blank'>"+results[i].title+"</a></span>"+ "<br>"+

1 answer

0

I believe you can solve this by using a template string (`between`crases) and interpolation (`Hello ${name}`).

I didn’t quite understand your code, but it would look something like this:

<a href= `google.maps.event.trigger(closest[${results[i].idx_closestMark}])`>
  • I was able to solve it: + " <a href = 'https://goo.gl/maps/sQ5zPMJEERaggz3g8' target= '_Blank'>"+Results[i]. title+"</a></span>"+ "<br>"+

Browser other questions tagged

You are not signed in. Login or sign up in order to post.