admin管理员组文章数量:1292225
Why this isn't true?
$('#myId') == document.getElementById("myId")
I'm using JQuery 1.4.2 and trying to insert a GMap into an div element.
So, this works:
new google.maps.Map(document.getElementById("myId"),myOptions);
but this doesn't
new google.maps.Map($("myId"),myOptions);
Why this isn't true?
$('#myId') == document.getElementById("myId")
I'm using JQuery 1.4.2 and trying to insert a GMap into an div element.
So, this works:
new google.maps.Map(document.getElementById("myId"),myOptions);
but this doesn't
new google.maps.Map($("myId"),myOptions);
Share
Improve this question
edited Jul 10, 2015 at 15:02
bobthemac
1,1726 gold badges26 silver badges60 bronze badges
asked Sep 15, 2010 at 23:17
santiagobasultosantiagobasulto
11.7k11 gold badges69 silver badges90 bronze badges
3 Answers
Reset to default 12You have a couple issues. First, ID selectors use #
. Second, $(...)
is a jQuery object, and you need to pass a DOM element.
Use $('#myId').get(0)
The get method.
It doesn't work because the google.maps.Map()
constructor expects a a DOM element, while the jQuery selector returns a jQuery object.
You may want to use:
new google.maps.Map($("#myId")[0], myOptions);
Further reading:
- Google Maps API Groups: Why doesn't jQuery selection work?
$('#myId') creates a jQuery selection, while GMap requires a DOM element. You can convert the jQuery selection into a DOM element by using the $().get function:
new google.maps.Map($("#myId").get(0), myOptions);
本文标签: JavaScriptJQueryGoogle Maps and (39myId39)getElementById(quotmyIdquot)Stack Overflow
版权声明:本文标题:javascript - JQuery, Google Maps and $('#myId') == getElementById("myId") - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741173649a2352111.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论