Creating a variable selector with jQuery?
<p>Let me clarify.</p>

<p>I have a giant loop which parses XML, places markers on a google map accordingly, and makes hidden divs, one per marker, which contain info relating to that marker.</p>

<p>The loop also places on each marker an event which opens an info window. The info window contains a button which must show that particular marker's div.</p>

<p>But I'm uncertain of how to do this. Here is most of the code below-- I have omitted the irrelevant earlier portions of the loop, and focused on the area where I am trying to attach a click event to each new button.</p>

<p>But I am uncertain of how to do this. See the comments in the code for a complete understanding.</p>

<pre><code>$(xml).find('sample').each(function () {

    var id = $(this).find('id long').text();

    /*there was code here which creates the other variables you see below*/

    var infoPage = '&lt;div style="display:none; position:absolute; top:0px; bottom:0px; width:100%;" id="' + id + 'Info"&gt;' + '&lt;p&gt;Number: ' + number + '&lt;/p&gt;' + '&lt;p&gt;ID: ' + id + '&lt;/p&gt;' + '&lt;p&gt;Rock type: ' + rockType + '&lt;/p&gt;' + '&lt;p&gt;Minerals: ' + minerals + '&lt;/p&gt;' + '&lt;p&gt;Regions: ' + regions + '&lt;/p&gt;' + '&lt;p&gt;Latitude: ' + latitude + '&lt;/p&gt;' + '&lt;p&gt;Longitude: ' + longitude + '&lt;/p&gt;' + '&lt;/div&gt;';

    //there was code here which inserts this div into the page

    //this line creates the button which appears inside the info window
    var contentString = '&lt;a href="" data-role="button" id="' + id + '"&gt;' + number + '&lt;/a&gt;';

    //this line creates the info window
    var infowindow = new google.maps.InfoWindow({
        content: contentString
    });

    /*Here is where I hit a problem. I now need to construct a line of jQuery which attaches to this particular button a click event. But it needs to do it for every new button in the loop, so that each button's click event is unique and opens its personal div. How do I construct a selector which will change with the loop to accomplish the desired result?*/
    $('#' + id).click(function () {
        $('#' + id + 'Info').show();
    });

    google.maps.event.addListener(marker, 'click', function () {
        infowindow.open(map, marker);
    });

});
</code></pre>
