I’m using the jQuery maphighlight plugin with a map of the U.S.
I have several states that are too small to put their abbreviations on them, so I have to put them to the side.
What I have done already is that when the user hovers on an abbreviation, the corresponding state is highlighted. That’s working fine.
The “problem” I have is that, although the code works, it looks too repetitive to me, I’ve tried to simplify/optimize it, but the error I get is that all abbreviations highlight one single state and not the corresponding one.
Here’s the code I have so far:
$(function() {
$('.map').maphilight();
$('#ma-link').mouseover(function(e) {
$('#ma').mouseover();
}).mouseout(function(e) {
$('#ma').mouseout();
}).click(function(e) { e.preventDefault(); });
$('#ri-link').mouseover(function(e) {
$('#ri').mouseover();
}).mouseout(function(e) {
$('#ri').mouseout();
}).click(function(e) { e.preventDefault(); });
$('#ct-link').mouseover(function(e) {
$('#ct').mouseover();
}).mouseout(function(e) {
$('#ct').mouseout();
}).click(function(e) { e.preventDefault(); });
$('#nj-link').mouseover(function(e) {
$('#nj').mouseover();
}).mouseout(function(e) {
$('#nj').mouseout();
}).click(function(e) { e.preventDefault(); });
$('#de-link').mouseover(function(e) {
$('#de').mouseover();
}).mouseout(function(e) {
$('#de').mouseout();
}).click(function(e) { e.preventDefault(); });
$('#md-link').mouseover(function(e) {
$('#md').mouseover();
}).mouseout(function(e) {
$('#md').mouseout();
}).click(function(e) { e.preventDefault(); });
});
Is there a way to simplify this?
Any help with this will be greatly appreciated.
Thanks.
No change to your HTML required. Just replace your block with this.