1

I need to know what area a user is hovering on an Image i've mapped. What i've tried is give different classes to the areas and using jQuery I detect which one is being hovered.

This is my html:

<img src="test.jpg"  usemap="#map" id="testMap"/>
    <map id="map" name="map">
        <area class="area1" shape="poly" alt="" title="" coords="37,459,145,378,111,347,17,436,25,446" href="" target="" />
        <area shape="poly" alt="" title="" coords="118,460,224,379,192,347,96,436" href="" target="" />
        <area class="area1" shape="poly" alt="" title="" coords="305,379,198,460,176,435,272,348" href="" target="" />
        <area shape="poly" alt="" title="" coords="350,349,385,379,272,464,276,457,257,436" href="" target="" />
        <area shape="poly" alt="" title="" coords="433,349,466,380,359,460,337,436" href="" target="" />
        <area shape="poly" alt="" title="" coords="512,348,545,379,432,464,437,456,415,436" href="" target="" />
        <area shape="poly" alt="" title="" coords="590,349,622,380,511,463,516,456,495,435,590,348" href="" target="" />
        <area shape="poly" alt="" title="" coords="670,348,703,380,594,460,573,435" href="" target="" />
        <area shape="poly" alt="" title="" coords="749,347,783,380,670,463,674,455,656,436" href="" target="" />
        <area shape="poly" alt="" title="" coords="830,349,863,380,752,461,733,436" href="" target="" />
        <area shape="poly" alt="" title="" coords="910,349,941,379,830,463,834,455,814,437" href="" target="" />
    </map>

And this is the script I've used to check for the hover state:

<script>
    $(document).ready(function(){
        if ($('.area1').is(':hover')) {
        alert('hovered');
    }
    });
    </script>

But I don't get any result.. Can someone explain me why?

MrUpsidown
  • 21,592
  • 15
  • 77
  • 131
LS_
  • 6,763
  • 9
  • 52
  • 88

1 Answers1

0

What about the following:

$('.area1').hover(function() {
    alert('hovered');
});

http://api.jquery.com/hover/

or

$('.area1').on('mouseenter', function () {
    alert('mouse enter');
});

http://api.jquery.com/on/

MrUpsidown
  • 21,592
  • 15
  • 77
  • 131