-1

Trying to generate Google Map from pure jQuery way I cant' render map when I use the ID selector as:

var map = new google.maps.Map($("#map_canvas"), mapOptions);

the maps is working when I use the finding element id in simple JavaScript method as:

var map = new google.maps.Map(document.getElementById("map_canvas"), mapOptions);

can you please help me to understand why this is happening?

Mona Coder
  • 6,212
  • 18
  • 66
  • 128

1 Answers1

3

Quick search revealed this:

It expects a DOM element, but $('#map_cavas') returns a jQuery object. If you want to use a jQuery selector, do:

var map = new google.maps.Map($("#map_canvas")[0], mapOptions);

Source: Google maps (V3) - Map container selector (using jquery)

Community
  • 1
  • 1
tymeJV
  • 103,943
  • 14
  • 161
  • 157
  • Hi tymeJV I updated the code as you posted but still not working! I also used the .get(0) method but nothing! – Mona Coder Jun 10 '13 at 18:05