Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8009707
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T18:31:26+00:00 2026-06-04T18:31:26+00:00

Let me clarify. I have a giant loop which parses XML, places markers on

  • 0

Let me clarify.

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.

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.

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.

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

$(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 = '<div style="display:none; position:absolute; top:0px; bottom:0px; width:100%;" id="' + id + 'Info">' + '<p>Number: ' + number + '</p>' + '<p>ID: ' + id + '</p>' + '<p>Rock type: ' + rockType + '</p>' + '<p>Minerals: ' + minerals + '</p>' + '<p>Regions: ' + regions + '</p>' + '<p>Latitude: ' + latitude + '</p>' + '<p>Longitude: ' + longitude + '</p>' + '</div>';

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

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

    //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);
    });

});
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T18:31:28+00:00Added an answer on June 4, 2026 at 6:31 pm

    First, give the same class to all the buttons

    var contentString = '<a href="" class="mybutton" data-role="button" id="' + id + '">' + number + '</a>';
    

    Second, bind the event handler to all the mybuttons

    $(document).on('click', '.mybutton', function() {
        $('#' + $(this).attr('id') + 'Info').show();
    });
    

    UPD: as @Felix Kling said – the important thing here is that you need to bind it once, outside the loop

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Let me clarify this a bit... I have a class that handles XML files.
First off, let me clarify the platforms we are using. We have an ASP.NET
First of all, let me clarify that I know you cannot have actual abstract
I have some query. First of all let's have an iPhone application flow which
i have a rails app which makes heavy use of activeresource and httparty to
The title is a bit weird, so let me clarify. I have two objects,
I have noticed that window.onunload event fires off AFTER page_load event which makes no
Let me clarify: I'm using standard jQuery autocomplete plugin (bassistanse.de) and bind it to
The caption is confusing. Let me clarify a bit: I'd like to provide events
I know this is very stupid question, but I wanted to clarify this. Let's

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.