Search code examples
javascripthtmlimageshapesarea

Get img tag id when click on map area of this image


I have some images-figures with map-area like this

image area

and i need get image id when click inside area zone
can i made it without custom area functional realisation with js?

UPD sandbox

UPD2 found second, other problem. first area zone (red), which covered by second image not clickable and z-index for area not working.

image problem

FINAL UPD
I wrote small custom function for mapping some objects.
Maybe it will help someone:
jsFiddle


Solution

  • I hope this is what you are looking for

    JS Fiddle Example : http://jsfiddle.net/g5Dy3/44/

    HTML

    <img id="dotted" src="image1.jpg" usemap="#ballmap" alt="sample" />
    <img id="solid" src="image2" usemap="#ballmap2" alt="sample" />
    
    <map name="ballmap">
        <area shape="circle" coords="210,120,90" href="#" alt="dotted ball" title="dotted ball" onclick="clickedMe(this);">
    </map>
    <map name="ballmap2">
        <area shape="circle" coords="126,90,70" href="#" alt="solid ball" title="solid ball" onclick="clickedMe(this);">
    </map> 
    

    JS

    function clickedMe(item) {
        var mapName;
        mapName = $(item).parent().attr('name');
        $('img').each(function(){
            if($(this).attr('usemap') == '#'+mapName){
                alert($(this).attr('id'));            
            }       
        });
    }