I have a map with individual numbered facilities marked with a dot that changes color when hovered or selected. When selected, text in a separate container changes content depending on which facility is selected.
I also have a legend of the numbers under the map. When the legend text is clicked, it also changes the text content of the container. Clicking on either the dot or legend individually works fine changing the color of the hovered and selected dots or legend text.
Now I'm trying to combine the effect of hovering over/clicking the dot to trigger the associated legend text to hover/become selected and vice-versa.
This is my very first attempt at jQuery so please be understanding! I've only been at this about a day. Reading as much as I can -- this is probably an easy solution, but I'm not seeing it. I tried making a new variable combining the dot and legend text and linking them through the shared facility name and that didn't work. I thought the on (bind) command would link the actions together, but that didn't work either. Any suggestions would be so greatly appreciated. Thanks in advance!
code
<!DOCTYPE html>
<html>
<head>
<script src="http://code.jquery.com/jquery-latest.js"></script>
</head>
<body>
<div class="map_container">
<a class="dot" style="left: 315px; top: 189px;" facility="bldg4" work="bldg4work"></a>
<a class="dot" style="left: 514px; top: 188px;" facility="bldg7" work="bldg7work"></a>
<div class="legend">
4. <a class="legt" facility="bldg4" work="bldg4work">Primary Clarifiers - West</a><br />
7. <a class="legt" facility="bldg7" work="bldg7work">Secondary Clarifiers</a><br />
</div>
</div>
<script>
$("a.dot, a.legt").on({click: function(){
$("a.dot").removeClass("selected");
$(this).addClass("selected");
$("a.legt").removeClass("selected");
$(this).addClass("selected");
var work = ".work_detail#" + $(this).attr("work");
var htmlCode = $(work).html();
$(".detail_container").fadeOut(500, function(){
$(".detail_container .work_detail").html(htmlCode);
$(".detail_container").fadeIn(500);
});
}
});
</script>
</body>
</html>
css
.map_container a.dot {
display: block;
height: 20px;
width: 20px;
background-image: url(../images/dots.png);
background-repeat: no-repeat;
background-position: 0px 0px;
cursor: pointer;
position: absolute;
}
.map_container a.dot:hover {
background-position: 0px -20px;
}
.map_container a.dot.selected {
background-position: 0px -40px;
}
.map_container a.legt {
font-family: Arial, Helvetica, sans-serif;
font-size: 1em;
color: #F00;
font-weight: bold;
text-decoration: none;
}
.map_container a.legt:hover {
font-family: Arial, Helvetica, sans-serif;
font-size: 1em;
color: #FF0;
font-weight: bold;
background-color: #630;
text-decoration: none;
}
.map_container a.legt.selected {
font-family: Arial, Helvetica, sans-serif;
font-size: 1em;
font-weight: bold;
color: #0F0;
background-color: #630;
}
I tried this for the hover -- I know the syntax is probably not correct, but am I close?
$('a.dot[facility*]').hover(function(){
$('a.legt[facility*]').toggleClass('a.legt.hover');
});
facility
andwork
are invalid attributes, you should usedata-facility
anddata-work
instead. – m90 Dec 27 '12 at 17:54data-
, read about it here – m90 Dec 27 '12 at 18:05