I have the following JQuery plugin:
$(function () {
$.fn.mapit = function (position, styles) {
var self = $(this);
var map = new google.maps.Map(self[0], {
center: position,
styles: styles
});
var marker = new google.maps.Marker({
position: position,
map: map
});
return $(this);
}
});
And I call it using something like:
google.load("maps", "3", callback: function() {
$("div#office").mapit({ lat: 38.73972, lng: -9.144263 }, [{"featureType":"all"}]);
});
The problem is when I call mapit and there is no div#office on the page I get the following error:
TypeError: a is undefined
What should I do in my plugin to avoid this?