Q:

jQuery and dynamic ID

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.

A:

You should put a class to the clickable elements
<a href="#" id="maptrigger-1" class="trigger">click</a>

and use
$('someParentOfAll.triggerElements').on('click','.trigger', function(){
    var mapid = 'map-' + this.id.split('-')[1],
        marker = $('#googlemap').gmap3({ get: { id: mapid } });

    google.maps.event.trigger(marker, 'click'); 
});

A:

Use the attribute starts with selector
$('[id^="maptrigger"]').live('click',function(){

And better to attach the events using .on() as .live() has been deprecated as of jQuery 1.7.0
$('[id^="maptrigger"]').on('click',function(){

