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 9152363
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T12:01:26+00:00 2026-06-17T12:01:26+00:00

I’m pretty new to javascript and I’m learning as I go along, so sorry

  • 0

I’m pretty new to javascript and I’m learning as I go along, so sorry if this is simple.

What I have is a bunch of markers displaying on the map, these are loaded from an array and displayed with a function. What I want to do is make a specific div pop up which is related to the marker that was clicked on. When another marker is clicked, that previous div closes and the new div opens up.

This is what I have so far, to get a concept of what I’m doing.

I imagine I would want to write a function that says… “If ‘Marker A’ is clicked, open up ‘div A’ and if ‘Marker B’ is clicked while ‘Marker A’ is open, then close ‘Div A’ and open up ‘Div B’.

Here’s my javascript.

 var markers = [
['Saving Grace', 43.652659,-79.412284],
['Starving Artist', 43.660281,-79.443570]
];

  // Standard google maps function
    function initialize() {
    var myLatlng = new google.maps.LatLng(43.655826,-79.383116);
    var image = 'http://www.brunchtoronto.com/images/marker-blue.png';
    var myOptions = {
        zoom: 13,
        center: myLatlng,
        mapTypeId: google.maps.MapTypeId.ROADMAP
    }

    map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);


    // Current Toggle function which displays Feature Box when marker is clicked
    function opendiv() {
        var ele = document.getElementById("div-feature");
                    ele.style.display = "block";                            
            } 


    var infowindow = new google.maps.InfoWindow();
    var marker, i;


    for (i = 0; i < markers.length; i++) {  
    marker = new google.maps.Marker({
    position: new google.maps.LatLng(markers[i][1], markers[i][2]),
    map: map,
    icon: image
    });


    google.maps.event.addListener(marker, 'click', (function(marker, i) {
        return function() {
            map.panTo(marker.getPosition());
            infowindow.setContent(markers[i][0]);
            infowindow.open(map, marker);
            opendiv();
            }   
        })(marker, i));
    }



}

And my HTML

<!-- Featued Window -->

    <div class="featured_window" id="div-feature" style="display: none">

                Stuff to display

    </div>

<!-- Saving Grace -->

    <div class="featured_window" id="div-sg" style="display: none">

        Stuff to display

    </div>
  • 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-17T12:01:27+00:00Added an answer on June 17, 2026 at 12:01 pm

    You need to have a relation between the marker and the div, currently there isn’t any.

    Instead of an ID like div-sg this could be e.g. div0 , where the number indicates the index of the marker.

    Then it’s no problem to access the div:

       //access the node
     var content=document.getElementById('div'+i)
       //create a copy of the node
     .cloneNode(true);
       //remove the id to avoid conflicts
     content.removeAttribute('id');
       //make it visible  
     content.style.display='block';
       //apply the content  and open the infoWindow 
     infowindow.setContent(content);
     infowindow.open(map, marker);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I have just tried to save a simple *.rtf file with some websites and
this is what i have right now Drawing an RSS feed into the php,
I have a small JavaScript validation script that validates inputs based on Regex. I
I have this code to decode numeric html entities to the UTF8 equivalent character.
This could be a duplicate question, but I have no idea what search terms
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
I don't have much knowledge about the IPv6 protocol, so sorry if the question
I'm not entirely sure how I managed to jack this up. http://pretty-senshi.com If you

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.