I’m rendering Google Maps markers with gmap3 jQuery plugin.
I’m triggering marker popups with clicks on menu links based on marker ID, which I can set with this plugin.
Marker gets ID (beside lat/long and popup text) with this code:
{latLng:[46.055221,14.504265], data:"some text", id:"map-1"}
Marker popup is triggered with this jQuery code:
$('#maptrigger-1').live('click',function(){
var marker = $('#googlemap').gmap3({ get: { id: 'map-1' } });
google.maps.event.trigger(marker, 'click');
});
and this HTML code:
<a href="#" id="maptrigger-1">click</a>
I don’t want to repeat jQuery code for every marker/ID (map-1/maptrigger-1, map2/maptrigger2, map3/maptrigger3), but I wasn’t successful so far.
Any help would be appreciated.
Use the attribute starts with selector
And better to attach the events using
.on()as.live()has been deprecated as ofjQuery 1.7.0