Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

JavaScript

Randy Wang
Randy Wang
9,291 Points

Adding Dynamic Map: $("#locations").prepend("<div id="map"></div>");

I'm working through the "Google Maps Integration" section and in the "Adding Dynamic Map" lesson, the line below does not work and throws an error in the console: "Uncaught SyntaxError: Unexpected identifier"

$("#locations").prepend("<div id="map"></div>");

When I remove the line then the rest of code works including removing the static maps. I've also tried leaving the "<div id="map"></div>" instead of trying to prepend it and the dynamic map shows up fine.

It seems other users have had the same problem but I did not see responses from instructors helping to explain why the line doesn't work.

3 Answers

Randy Wang
Randy Wang
9,291 Points

Looks like first storing the map div in a variable works. No idea why...

    var mapDiv = "<div id='map'></div>";
    $("#locations").prepend(mapDiv);

relook at the original code.. then pay more attention to the double quotes. You can not have double quotes within double quotes.

Randy Wang
Randy Wang
9,291 Points

Thanks Frank! Looks like that was the issue.