I am trying to link some markers on a Google map and several divs outside the map. If I hover over the marker on the map, I want to change the background color in a separate Div. If I have only one marker, it works fine, but if I have five, as in the example, only the last one from the list will be displayed.
Why? What's wrong? Can anybody help me?
function initialize() { var locations = [ ['E021066', 39.521753693611515, 2.480292320251465, 4], ['E033012', 39.52724876810637, 2.48166561126709, 5], ['E023016', 39.50193802307746, 2.4660873413085938, 3], ['E019512', 39.522349566080855, 2.4886178970336914, 2], ['E032023', 39.510927787044295, 2.4994325637817383, 1] ]; var latlng = new google.maps.LatLng(39.5075442, 2.476614799999993); var myOptions = { zoom: 12, center: latlng, mapTypeId: google.maps.MapTypeId.SATELLITE }; var map = new google.maps.Map(document.getElementById("map_canvas"), myOptions); var infowindow = new google.maps.InfoWindow(); var marker, i; var image1 = 'images/marker1.png'; var image2 = 'images/marker2.png'; for (i = 0; i < locations.length; i++) { **var id = locations[i][0];** marker = new google.maps.Marker({ position: new google.maps.LatLng(locations[i][1], locations[i][2]), map: map, icon: image1 }); google.maps.event.addListener(marker, 'click', (function(marker, i) { return function() { marker.setImage("images/marker.png"); } })(marker, i)); google.maps.event.addListener(marker, 'mouseover', function() { this.setIcon(image2); **id.style.backgroundColor='#ccc';** }); google.maps.event.addListener(marker, 'mouseout', function() { this.setIcon(image1); **id.style.backgroundColor='#fff';** }); } }