views:

242

answers:

3

Using JQuery, how do I change a map icon whenever I mouse hover over a row in an HTML table/div?

Here is an example:

http://www.sfsunriseidx.com/homes/94131/?uuid=9ed7269b-5327-4c88-ba15-f700ed343d69&source=REDIR

Notice when you mouse hover over a home listing on the left, the corresponding map icon on the right changes.

Question: how do I emulate this functionality using JQuery?


Update: It was suggested below that an ID linked the two elements. If that is the case, how would you still accomplish this?

A: 

Probably both elements are linked by a ID..

TiuTalk
So if an ID does linked them, then how would you do this?
BillT
+2  A: 

Use the for="" attribute in html, like

<a href="page.html" for="mapIcon4" class="mapHover">Hover Link</a>

On the image:

<img id="mapIcon4" src="myImg.png" />

jQuery, using the hover function to animate the corresponding ID, the same one in the for:

$(".mapHover").hover(function() {
  $("#" + $(this).attr('for')).animate({"left": "-=50px"}, "slow");
}, function() {
  $("#" + $(this).attr('for')).animate({"right": "+=50px"}, "slow");
});
Nick Craver
@Nick Craver, this seems to be close. So then how do I use this then with Google Maps when the icon on the map corresponds with a CreateMarker() function
BillT
A: 

Something like this:

$(document).ready(function() {
    var googleMap = $("#googleMaps");

    $('a', '#mapLinks').hover(function() {
        var index = $(this).index(this);
        $('img:eq(' + index + ')', googleMap).animate({
            width: '+=10%'
        });
    }, function() {
        var index = $(this).index(this);
        $('img:eq(' + index + ')', googleMap).animate({
            width: '-=10%'
        });
    });
});

Just make sure you change the "#googleMaps" and "#mapLinks" thing :)

TiuTalk